Opened 4 years ago

Closed 4 years ago

#14673 closed (invalid)

MultipleHiddenInput unbound form

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

Description

I'm using a MultipleHiddenInput widget and it seems it only renders the hidden inputs if there is a value bound to the field as opposed to HiddenInput which always renders a hidden input.
I hoped it will render a least one hidden input if the form is not bound.

Change History (3)

comment:1 follow-up: Changed 4 years ago by humanfromearth

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This patch seems to solve the problem

===================================================================
--- django/forms/widgets.py	(revision 14540)
+++ django/forms/widgets.py	(working copy)
@@ -253,7 +253,7 @@
         self.choices = choices
 
     def render(self, name, value, attrs=None, choices=()):
-        if value is None: value = []
+        if value is None: value = [None]
         final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
         id_ = final_attrs.get('id', None)
         inputs = []

comment:2 in reply to: ↑ 1 Changed 4 years ago by humanfromearth

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

Actually setting value = [] is the correct solution. force_unicode transforms None into u'None' which is not good.

Replying to humanfromearth:

This patch seems to solve the problem

===================================================================
--- django/forms/widgets.py	(revision 14540)
+++ django/forms/widgets.py	(working copy)
@@ -253,7 +253,7 @@
         self.choices = choices
 
     def render(self, name, value, attrs=None, choices=()):
-        if value is None: value = []
+        if value is None: value = [None]
         final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
         id_ = final_attrs.get('id', None)
         inputs = []

comment:3 Changed 4 years ago by russellm

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

I don't think what you're describing makes sense. MultipleHiddenInput represents multiple values as a series of hidden inputs. If there aren't any currently selected values,then there aren't any hidden inputs. I'm not sure I see how it could be meaningfully interpreted any other way.

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