Opened 7 years ago

Last modified 3 years ago

#11836 new New feature

Missing django.forms.widgets.MultiWidget hidden counterpart

Reported by: sayane Owned by: nobody
Component: Forms Version:
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


Sometimes it's useful to hide bound field with .as_hidden method. But it's not possible if this field uses MultiWidget. MultiValueWidget doesn't work, because it generates different html names than MultiWidget.

Attachments (1)

multiplehiddeninput_unique_names.diff (2.8 KB) - added by brianmacdonald 6 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 7 years ago by sayane

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Oops. Not MultiValueWidget but MultipleHiddenInput.

comment:2 Changed 7 years ago by russellm

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

Marking this invalid, because I'm not sure I understand the use case. A full example of code that should (but doesn't) work is required.

comment:3 Changed 7 years ago by sayane

For now i'm not shure what it was about. I'll try find this project and I'll provide more informations later.

comment:4 Changed 7 years ago by sayane

I found that.

MultiWidget generates html names like this: "name_0", "name_1", "name_2", "name_x"...
MultipleHiddenInput uses only one name: "name" (but multiple times).

So If i'm using MultiValueField and I'll render a field with as_hidden method (this will put all data in name "name"), then field won't be able to get data from request.POST.

This is why there are SplitDateTimeWidget and SplitHiddenDateTimeWidget in django/forms/ I think there should be a hidden field that works with MultiWidget.

comment:5 Changed 7 years ago by sayane

Here is a simple example. MultiLineAddressWidget is a subclass of MultiWidget.

In [26]: w = MultiLineAddressWidget()

In [27]: w.render("myname", ["line1", "line2", "line3"])
Out[27]: u'<input type="text" name="myname_0" value="line1" /><br /><input type="text" name="myname_1" value="line2" /><br /><input type="text" name="myname_2" value="line3" />'

In [28]: w = forms.MultipleHiddenInput()

In [29]: w.render("myname", ["line1", "line2", "line3"])
Out[29]: u'<input type="hidden" name="myname" value="line1" />\n<input type="hidden" name="myname" value="line2" />\n<input type="hidden" name="myname" value="line3" />'

In [30]: 

In [36]: data = {'myname': ['line1', 'line2', 'line3']}

In [37]: w = forms.MultipleHiddenInput()

In [38]: w.value_from_datadict(data, {}, "myname")
Out[38]: ['line1', 'line2', 'line3']

In [39]: w = MultiLineAddressWidget()

In [40]: w.value_from_datadict(data, {}, "myname")
Out[40]: [None, None, None]

I forgot to say that MultiValueField uses MultipleHiddenInput as default hidden widget.

comment:6 Changed 7 years ago by sayane

  • Resolution invalid deleted
  • Status changed from closed to reopened

comment:7 Changed 7 years ago by jacob

  • milestone set to 1.2
  • Triage Stage changed from Unreviewed to Accepted

comment:8 Changed 7 years ago by ubernostrum

  • milestone 1.2 deleted

1.2 is feature-frozen, moving this feature request off the milestone.

Changed 6 years ago by brianmacdonald

comment:9 Changed 6 years ago by brianmacdonald

  • Has patch set
  • Version 1.1 deleted

Attached a patch that adds the feature as a argument of MultipleHiddenInput.

comment:10 Changed 5 years ago by julien

  • Patch needs improvement set
  • Severity set to Normal
  • Type set to New feature

The tests would need to be rewritten using unittests since this is now Django's preferred way.

comment:11 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:12 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:13 Changed 3 years ago by aaugustin

  • Status changed from reopened to new
Note: See TracTickets for help on using tickets.
Back to Top