Opened 12 years ago

Closed 12 years ago

#3193 closed defect (fixed)

[patch] modify as_hidden() to handle MultipleChoiceField correctly

Reported by: Honza Král <Honza.Kral@…> Owned by: Adrian Holovaty
Component: Forms Version: master
Severity: normal Keywords: as_hidden MultipleChoiceField
Cc: Honza.Kral@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It is a quick and dirty patch (works though ;) ), but since the information on what field requires list as value is gone, I had to use the Field class to identify the correct value. I don't like the idea of checking for Field;s class every time I render a hidden field, but it was the best I could do without going further into the code.

The added widget class renders multiple <input type="hidden" .. > tags (one for every checked option).

I will be glad for any feedback and/or comments.

Attachments (1)

multi_hidden.patch (1.9 KB) - added by Honza Král <Honza.Kral@…> 12 years ago.
implementation of MultipleHiddenInput

Download all attachments as: .zip

Change History (4)

Changed 12 years ago by Honza Král <Honza.Kral@…>

Attachment: multi_hidden.patch added

implementation of MultipleHiddenInput

comment:1 Changed 12 years ago by Adrian Holovaty

Hmmm, yeah, doing an isinstance there seems a bit inelegant. I'll play around with some other implementations... Maybe it's as easy as giving the Field class a hidden_field attribute, which MultipleChoiceField would override.

comment:2 Changed 12 years ago by Honza Král <Honza.Kral@…>

I originally thought of using the requires_list field, but it was no longer there so I decided not to add another field with roughly the same meaning...

btw. it seems more natural to me for as_hidden, as_text etc to be handled by Field and not BoundField - the latter knows nothing about the data (as demonstrated in this problem) and therefore cannot adapt its behaviour, the Field seems better suited for this.

comment:3 Changed 12 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [4298]) Fixed #3193 -- newforms: Modified as_hidden() to handle MultipleChoiceField correctly. Thanks for the report, Honza Kral

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