#27445: RadioSelect widget does not work for NullBooleanField
-------------------------------------+-------------------------------------
Reporter: Anne | Owner: nobody
Fleischer |
Type: New | Status: new
feature |
Component: Forms | Version: master
Severity: Normal | Keywords: NullBooleanField,
Triage Stage: | RadioSelect
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The default widget for NullBooleanFields result in a selectbox with 3
options being shown.
In my opinion it should also be possible to represent those 3 options by
radio inputs.
However, simply changing the form widget for a NullBooleanField to be a
RadioSelect, will result in no form inputs whatsoever being shown.
Here is the code to reproduce it:
{{{
from django.db import models
class MyTestModel(models.Model):
foo = models.NullBooleanField(blank=True, null=True)
}}}
{{{
from django import forms
class MyTestModelForm(forms.ModelForm):
class Meta:
model = MyTestModel
fields = ('foo',)
widgets = {
'foo': forms.RadioSelect,
}
}}}
I'm not sure if this is a bug or if the bahaviour is intentional.
As a workaround I tried to just initialize the choices manually in the
widget, like this:
{{{
widgets = {
'foo': forms.RadioSelect(choices=(('', 'Unknown'), ('1',
'Yes'), ('0', 'No'))),
}
}}}
However, this works in terms of storing the correct value, but it does not
render the selected radio input as checked.
I'd like to work in this if someone can confirm that this behaviour is not
intended.
--
Ticket URL: <https://code.djangoproject.com/ticket/27445>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.deb12bdc78c3ccc2aa7793b69abacd52%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.