Opened 16 years ago
Closed 6 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)
Change History (19)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → 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 by , 16 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 , 16 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 , 16 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 , 16 years ago
| Resolution: | invalid |
|---|---|
| Status: | closed → reopened |
comment:7 by , 16 years ago
| milestone: | → 1.2 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:8 by , 16 years ago
| milestone: | 1.2 |
|---|
1.2 is feature-frozen, moving this feature request off the milestone.
by , 15 years ago
| Attachment: | multiplehiddeninput_unique_names.diff added |
|---|
comment:9 by , 15 years ago
| Has patch: | set |
|---|---|
| Version: | 1.1 |
Attached a patch that adds the feature as a argument of MultipleHiddenInput.
comment:10 by , 15 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:13 by , 13 years ago
| Status: | reopened → new |
|---|
comment:14 by , 6 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:15 by , 6 years ago
| Patch needs improvement: | unset |
|---|
I've created a pull request to progress this issue.
comment:16 by , 6 years ago
| Type: | New feature → Bug |
|---|
comment:17 by , 6 years ago
| Type: | Bug → New feature |
|---|
comment:18 by , 6 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | assigned → closed |
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).
Oops. Not MultiValueWidget but MultipleHiddenInput.