Opened 9 years ago

Closed 8 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@… 9 years ago.
patch to add groupedSelect widget that works with existing ChoiceField class
example.py (676 bytes) - added by tbarta@… 9 years ago.
example usage of GroupedSelect
grouped_select.diff (2.4 KB) - added by thejaswi_puthraya 8 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 9 years ago by Michael Radziej <mir@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 9 years ago by adrian

  • Triage Stage changed from Design decision needed to Accepted

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 9 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 9 years ago by tbarta@…

patch to add groupedSelect widget that works with existing ChoiceField class

Changed 9 years ago by tbarta@…

example usage of GroupedSelect

comment:4 Changed 9 years ago by tbarta@…

  • Has patch set

comment:5 Changed 9 years ago by anonymous

  • Summary changed from ChoiceField should allow for nested choice sets to [patch] ChoiceField should allow for nested choice sets

comment:6 Changed 8 years ago by thejaswi_puthraya

  • Owner changed from nobody to thejaswi_puthraya

Changed 8 years ago by thejaswi_puthraya

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

comment:7 Changed 8 years ago by thejaswi_puthraya

  • Cc changed from tbarta@gmail.com to tbarta@gmail.com,
  • Keywords sprintdec01 added
  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 8 years ago by mtredinnick

  • Triage Stage changed from Ready for checkin to Accepted

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 8 years ago by russellm

  • Resolution set to duplicate
  • Status changed from new to closed

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