Opened 9 years ago

Last modified 6 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 8 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 9 years ago by Sayane

Oops. Not MultiValueWidget but MultipleHiddenInput.

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

Resolution: invalid
Status: newclosed

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 9 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 9 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 9 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 9 years ago by Sayane

Resolution: invalid
Status: closedreopened

comment:7 Changed 9 years ago by Jacob

milestone: 1.2
Triage Stage: UnreviewedAccepted

comment:8 Changed 9 years ago by James Bennett

milestone: 1.2

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

Changed 8 years ago by brianmacdonald

comment:9 Changed 8 years ago by brianmacdonald

Has patch: set
Version: 1.1

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

comment:10 Changed 8 years ago by Julien Phalip

Patch needs improvement: set
Severity: Normal
Type: New feature

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

comment:11 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 Changed 7 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 Changed 6 years ago by Aymeric Augustin

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