Opened 8 years ago

Closed 8 years ago

#3193 closed defect (fixed)

[patch] modify as_hidden() to handle MultipleChoiceField correctly

Reported by: Honza Král <Honza.Kral@…> Owned by: adrian
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: UI/UX:

Description

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@…> 8 years ago.
implementation of MultipleHiddenInput

Download all attachments as: .zip

Change History (4)

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

implementation of MultipleHiddenInput

comment:1 Changed 8 years ago by adrian

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 8 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 8 years ago by adrian

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

(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