[Django] #20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do not render nested option sets correctly

45 views
Skip to first unread message

Django

unread,
Aug 17, 2013, 11:16:14 PM8/17/13
to django-...@googlegroups.com
#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" />
((&#39;vinyl&#39;, &#39;Vinyl&#39;), (&#39;cd&#39;, &#39;CD&#39;))
</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.

Django

unread,
Aug 18, 2013, 2:28:14 PM8/18/13
to django-...@googlegroups.com
#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do
not render nested option sets correctly
-------------------------+------------------------------------

Reporter: dyve | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: choices | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------+------------------------------------
Changes (by claudep):

* needs_docs: => 0
* needs_better_patch: => 0
* version: 1.5 => master
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/20931#comment:1>

Django

unread,
Aug 29, 2013, 9:20:00 PM8/29/13
to django-...@googlegroups.com
#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do
not render nested option sets correctly
-------------------------+------------------------------------

Reporter: dyve | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: choices | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------+------------------------------------
Changes (by carljm):

* cc: carljm (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/20931#comment:2>

Django

unread,
Sep 12, 2013, 11:02:58 AM9/12/13
to django-...@googlegroups.com
#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do
not render nested option sets correctly
-------------------------+-------------------------------------
Reporter: dyve | Owner: anonymous
Type: Bug | Status: assigned

Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: choices | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------
Changes (by cbabs):

* status: new => assigned
* owner: nobody => anonymous


--
Ticket URL: <https://code.djangoproject.com/ticket/20931#comment:3>

Django

unread,
Sep 12, 2013, 11:04:16 AM9/12/13
to django-...@googlegroups.com
#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do
not render nested option sets correctly
-------------------------+------------------------------------
Reporter: dyve | Owner: cbabs

Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: choices | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------+------------------------------------
Changes (by cbabs):

* owner: anonymous => cbabs


--
Ticket URL: <https://code.djangoproject.com/ticket/20931#comment:4>

Django

unread,
Sep 19, 2013, 8:26:30 AM9/19/13
to django-...@googlegroups.com
#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do
not render nested option sets correctly
-------------------------+------------------------------------
Reporter: dyve | Owner: cbabs
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: choices | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------+------------------------------------

Comment (by cbabs):

Cannot find a "RadioSelectMultiple" or "CheckBoxSelect" widget anywhere in
Django. Keeping RadioSelect & CheckboxSelectMultiple, but ignoring those
two.

--
Ticket URL: <https://code.djangoproject.com/ticket/20931#comment:5>

Django

unread,
Sep 26, 2013, 11:42:37 AM9/26/13
to django-...@googlegroups.com
#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do
not render nested option sets correctly
-------------------------+------------------------------------
Reporter: dyve | Owner: cbabs
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: choices | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------+------------------------------------

Comment (by cbabs):

Submitted pull request. https://github.com/django/django/pull/1683

--
Ticket URL: <https://code.djangoproject.com/ticket/20931#comment:6>

Django

unread,
Sep 28, 2013, 8:34:48 PM9/28/13
to django-...@googlegroups.com
#20931: RadioSelect, RadioSelectMultiple, CheckBoxSelect, CheckBoxSelectMultiple do
not render nested option sets correctly
-------------------------+------------------------------------
Reporter: dyve | Owner: cbabs
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed

Keywords: choices | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------+------------------------------------
Changes (by Julien Phalip <jphalip@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a834bc84d8c76d4a7016ac4db4f631a8bcaa3d0b"]:
{{{
#!CommitTicketReference repository=""
revision="a834bc84d8c76d4a7016ac4db4f631a8bcaa3d0b"
Fixed #20931 -- Fixed select widgets nested choice rendering

ChoiceFieldRenderer was not rendering nested choices. Added recursion
to ChoiceFieldRenderer to take nested choices and render them as
<ul>'s.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20931#comment:7>

Reply all
Reply to author
Forward
0 new messages