Opened 11 years ago

Last modified 6 years ago

#7664 new New feature

MultiWidget to support named sub widgets

Reported by: Collin Anderson Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: multiwidget
Cc: cmawebsite@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It would be nice if MultiWidget would support names for its sub widgets.

Currently if

widgets = (TextInput(attrs=attrs), TextInput(attrs=attrs))

you get something like this:

<input type="text" name="name_0"><input type="text" name="name_1">

Which is a bit ugly.

I would like to see something like one of these:

widgets = (TextInput(attrs=attrs), TextInput(attrs=attrs))
names = ('date', 'time')


widgets = (('date', TextInput(attrs=attrs)), ('time', TextInput(attrs=attrs)))

These would render to something like this:

<input type="text" name="name_date"><input type="text" name="name_time">

Attachments (1)

7664.diff (3.7 KB) - added by Koen Biermans 8 years ago.
patch to allow passing names for widgets into MultiWidget

Download all attachments as: .zip

Change History (6)

comment:1 Changed 11 years ago by Matt McClanahan

Component: Uncategorizeddjango.newforms
Keywords: multiwidget added
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 8 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:3 Changed 8 years ago by Jacob

Easy pickings: unset
Triage Stage: Design decision neededAccepted
UI/UX: unset

Yes, this is a good idea.

Changed 8 years ago by Koen Biermans

Attachment: 7664.diff added

patch to allow passing names for widgets into MultiWidget

comment:4 Changed 8 years ago by Koen Biermans

Has patch: set
Needs documentation: set

Added a small patch which allows passing names into MultiWidget as suggested.

comment:5 Changed 6 years ago by anonymous

Please also add the ability to override the _ separator. Creating a multiwidget for autocompletion ends up making field_1 and field_2 in POST when I'd really like to be able to generate field and field_text, because keeping field will make sure using the widget doesn't break any tests that use POSTdata. There are workarounds, but I feel like it's not something so complicated it deserves its own hack.

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