Opened 10 years ago

Closed 9 years ago

#3442 closed (duplicate)

[patch] ChoiceField should allow for nested choice sets

Reported by: pmpowell@… Owned by: Thejaswi Puthraya
Component: Forms Version: master
Severity: Keywords: sprintdec01
Cc: tbarta@…, Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

It would be really useful for the ChoiceField choices parameter to allow grouped sets of chioces (much like the Admin class allows for grouped fields). That way, the default widget could output HTML which encloses groups of OPTION tags within OPTGROUP tags.

Attachments (3)

widgets.diff (2.2 KB) - added by tbarta@… 10 years ago.
patch to add groupedSelect widget that works with existing ChoiceField class
example.py (676 bytes) - added by tbarta@… 10 years ago.
example usage of GroupedSelect
grouped_select.diff (2.4 KB) - added by Thejaswi Puthraya 9 years ago.
Added the GroupSelect Widget to django.newforms.extras.widgets and added support for unicode and mark_safe

Download all attachments as: .zip

Change History (12)

comment:1 Changed 10 years ago by Michael Radziej <mir@…>

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 10 years ago by Adrian Holovaty

Triage Stage: Design decision neededAccepted

Sure, that'd be a pretty good improvement. Please implement this as GroupedChoiceField and put it in django/newforms/extras, along with a GroupedChoiceWidget.

comment:3 Changed 10 years ago by tbarta@…

Cc: tbarta@… added

Do you really need a new GroupedChoiceField for this? For validation purposes, it's entirely identical (the grouping doesn't affect the HTML value at all). All you need is a way to provide grouping for rendering. As ChoiceField uses Select as a default widget, this could be done by addding a GroupedSelect that handles the grouping (either as a mapping of group-label => input-value or the other way around).

I'll work on a patch for this... it seems like unnecessary duplication to have a separate Field.

Changed 10 years ago by tbarta@…

Attachment: widgets.diff added

patch to add groupedSelect widget that works with existing ChoiceField class

Changed 10 years ago by tbarta@…

Attachment: example.py added

example usage of GroupedSelect

comment:4 Changed 10 years ago by tbarta@…

Has patch: set

comment:5 Changed 10 years ago by anonymous

Summary: ChoiceField should allow for nested choice sets[patch] ChoiceField should allow for nested choice sets

comment:6 Changed 9 years ago by Thejaswi Puthraya

Owner: changed from nobody to Thejaswi Puthraya

Changed 9 years ago by Thejaswi Puthraya

Attachment: grouped_select.diff added

Added the GroupSelect Widget to django.newforms.extras.widgets and added support for unicode and mark_safe

comment:7 Changed 9 years ago by Thejaswi Puthraya

Cc: tbarta@gmail.comtbarta@gmail.com,
Keywords: sprintdec01 added
Triage Stage: AcceptedReady for checkin

comment:8 Changed 9 years ago by Malcolm Tredinnick

Triage Stage: Ready for checkinAccepted

How is this different from #4412? At the moment, we are favouring committing #4412 once newforms-admin has merged, so unless this adds any significantly extra functionality, let's close this as a duplicate of #4412.

comment:9 Changed 9 years ago by Russell Keith-Magee

Resolution: duplicate
Status: newclosed

Agreed - this is a dupe of #4412, which has a better integrated and more complete implementation (including docs and tests).

Note: See TracTickets for help on using tickets.
Back to Top