#29059: Widget optgroup is not grouping choices with no group
------------------------------------------------+------------------------
Reporter: Riccardo Di Virgilio | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
I'm having problems writing template for custom controls (a bootstrap
button bar) using optgroup.
the problem is that optgroup is not grouping choices without groups, this
makes very hard to create several button bars that grouped togheter:
{{{
from django.forms.widgets import ChoiceWidget
w = ChoiceWidget(choices = [
("one", 1),
("two", 2), [
"italian", (
("uno", 1),
("due", 2)
)
]
])
}}}
now see how choices are grouped from optgroup:
{{{
import json
print(json.dumps(w.optgroups("name", "one"), indent = 4))
}}}
{{{
[
[
null,
[
{
"name": "name",
"value": "one",
"label": 1,
"selected": true,
"index": "0",
"attrs": {
"checked": true
},
"type": null,
"template_name": null
}
],
0
],
[
null,
[
{
"name": "name",
"value": "two",
"label": 2,
"selected": false,
"index": "1",
"attrs": {},
"type": null,
"template_name": null
}
],
1
],
[
"italian",
[
{
"name": "name",
"value": "uno",
"label": 1,
"selected": false,
"index": "2_0",
"attrs": {},
"type": null,
"template_name": null
},
{
"name": "name",
"value": "due",
"label": 2,
"selected": false,
"index": "2_1",
"attrs": {},
"type": null,
"template_name": null
}
],
2
]
]
}}}
this means that if choices are flats (no groups) you are getting a number
of groups that is the same of the number of choices, and in order to fix
this you need to use the grouping filters on the template in order to
regroup choices.
I think this is a bug, and flat choices should be grouped together as None
by optgroup method
thanks
--
Ticket URL: <https://code.djangoproject.com/ticket/29059>
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/061.33d626ba83e801dc77cf9f34ca391cf3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.