Opened 7 years ago

Last modified 2 years ago

#7664 new New feature

MultiWidget to support named sub widgets

Reported by: CollinAnderson 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

Description

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')

or

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 koenb 4 years ago.
patch to allow passing names for widgets into MultiWidget

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by mattmcc

  • Component changed from Uncategorized to django.newforms
  • Keywords multiwidget added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 4 years ago by jacob

  • Easy pickings unset
  • Triage Stage changed from Design decision needed to Accepted
  • UI/UX unset

Yes, this is a good idea.

Changed 4 years ago by koenb

patch to allow passing names for widgets into MultiWidget

comment:4 Changed 4 years ago by koenb

  • Has patch set
  • Needs documentation set

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

comment:5 Changed 2 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