Opened 7 years ago

Closed 7 years ago

#8655 closed (duplicate)

MultiValueField does not render correctly with as_hidden

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


MultiValueField needs to define hidden_widget = MultipleHiddenInput so that it will work properly when rendered with as_hidden(). However, MultipleHiddenInput still doesn't render IDs the same way as MultiWidget does, so MultiWidget's value_from_datadict will not find the values that MultipleHiddenInput has rendered. Or something like that. I'm concerned that trying to fix MultipleHiddenInput to work with MultiValueField will break MultipleChoiceField, so fixing this may require another Widget class.

A concrete example for this is using form preview with a SplitDateTimeField. The preview page renders all fields with as_hidden(), which creates a field like

<input type="hidden" name="delay_start" value="[u&#39;2008-08-29&#39;, u&#39;00:00:00&#39;]" id="formtools_delay_start" />

...which can't be turned back into valid data. It needs to render multiple hidden fields like:

<input type="hidden" name="delay_start_0" value="2008-08-29" id="formtools_delay_start_0" />
<input type="hidden" name="delay_start_1" value="00:00:00" id="formtools_delay_start_1" />

Using MultipleHiddenInput creates 2 hidden fields, but does not append the _i to each name and ID, so the data still does not get read back correctly by the form.

Attachments (1)

splithidden_8714.diff (4.2 KB) - added by bthomas 7 years ago.
A new widget for rendering a split input field as multiple hidden fields

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by bthomas

A new widget for rendering a split input field as multiple hidden fields

comment:1 Changed 7 years ago by bthomas

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset

Attached patch with a new SplitHiddenInput widget, which is an appropriate replacement for MultiWidget when a hidden field is needed. SplitDateTimeField now uses a class derived from it for its hidden_widget. Needs tests.

comment:2 Changed 7 years ago by bthomas

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

Looks like this was just fixed by [8816] for ticket #7975

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