Opened 14 years ago

Closed 14 years ago

#14673 closed (invalid)

MultipleHiddenInput unbound form

Reported by: Alexandru Plugaru 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: no UI/UX: no

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 by Alexandru Plugaru, 14 years ago

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 = []

in reply to:  1 comment:2 by Alexandru Plugaru, 14 years ago

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 by Russell Keith-Magee, 14 years ago

Resolution: invalid
Status: newclosed

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