Opened 15 years ago

Closed 5 years ago

#11836 closed New feature (wontfix)

Missing django.forms.widgets.MultiWidget hidden counterpart

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

Description

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 14 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 by Sayane, 15 years ago

Oops. Not MultiValueWidget but MultipleHiddenInput.

comment:2 by Russell Keith-Magee, 15 years ago

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

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

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/widgets.py. I think there should be a hidden field that works with MultiWidget.

comment:5 by Sayane, 15 years ago

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

Resolution: invalid
Status: closedreopened

comment:7 by Jacob, 15 years ago

milestone: 1.2
Triage Stage: UnreviewedAccepted

comment:8 by James Bennett, 15 years ago

milestone: 1.2

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

by brianmacdonald, 14 years ago

comment:9 by brianmacdonald, 14 years ago

Has patch: set
Version: 1.1

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

comment:10 by Julien Phalip, 14 years ago

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 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 by Aymeric Augustin, 12 years ago

Status: reopenednew

comment:14 by David Smith, 5 years ago

Owner: changed from nobody to David Smith
Status: newassigned

comment:15 by David Smith, 5 years ago

Patch needs improvement: unset

I've created a pull request to progress this issue.

https://github.com/django/django/pull/12567

comment:16 by Mariusz Felisiak, 5 years ago

Type: New featureBug

comment:17 by Mariusz Felisiak, 5 years ago

Type: BugNew feature

comment:18 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: assignedclosed

MultipleHiddenInput was created as a hidden_widget for MultipleChoiceField (see fb60a6ff0acc84417ced061e83bb170fff351b59). It handles multiple hidden widgets for fields that have a list of values (see docs), so the same names for all inputs is a desired behavior.

You shouldn't use it as a hiddent_widget for MultiValueField because it's a different use case (multiple fields vs. multiple values).

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