#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect,
CheckBoxSelectMultiple do
not render nested option sets correctly
----------------------------+---------------------
Reporter: dyve | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Keywords: choices
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------
The `Select` widget is the default widget to handle fields that make use
of `choices`. These are commonly rendered as a HTML `select`, as
implemented for `django.forms.widgets.Select`.
Sometimes a series of radio buttons or checkboxes is a better fir for the
UI. Django supports this by implementing widgets that can stand in for
`Select`. These are `RadioSelect`, `RadioSelectMultiple`,
`CheckBoxSelect`, `CheckBoxSelectMultiple`.
The choices to render are implemented as a n iterable of 2-tuples as
documented here:
https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices
As stated in the documentation, `choices` can be grouped for
organizational purposes. The example given:
{{{
MEDIA_CHOICES = (
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
),
('unknown', 'Unknown'),
)
}}}
When using a `Select` or `SelectMultiple` widget, these groups are
rendered as HTML `optgroup` elements. This is correct.
When using any of the other widgets mentioned, the organizational groups
are not taken into account when rendering the widget. Instead, the entire
group is forced to text without escaping, resulting in a single widget for
each group, with the text representation of the list as its label
(newlines and spaces added for better readability):
{{{
<label for="id_category3_0">
<input id="id_category3_0" name="category3" placeholder="Category3"
title="" type="radio" value="Audio" />
(('vinyl', 'Vinyl'), ('cd', 'CD'))
</label>
}}}
The solution for this would be take have the renders of these widgets
mimic the behavior of `Select.render_options`, but instead of `optgroup`
an extra level of `ul` would have to be generated. In pseudo-HTML, for the
given example:
{{{
<ul>
<li>
Audio
<ul>
<li>(input element for vinyl</li>
<li>(input element for CD</li>
</ul>
</li>
....
</ul>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20931>
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/047.bed97cabb55c360638440dae42642f1c%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.