Commit d75e23ce authored by Joseph Kocherhans's avatar Joseph Kocherhans
Browse files

[1.1.X] Fixed #9336. Changed CheckboxInput to render 'True' and 'False' input...

[1.1.X] Fixed #9336. Changed CheckboxInput to render 'True' and 'False' input strings as checked or not instead of as a value attribute. Backport of r12556 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12557 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 778b7bcd
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -384,7 +384,12 @@ class CheckboxInput(Widget):
            # A missing value means False because HTML form submission does not
            # send results for unselected checkboxes.
            return False
        return super(CheckboxInput, self).value_from_datadict(data, files, name)
        value = data.get(name)
        # Translate true and false strings to boolean values.
        values =  {'true': True, 'false': False}
        if isinstance(value, basestring):
            value = values.get(value.lower(), value)
        return value

    def _has_changed(self, initial, data):
        # Sometimes data or initial could be None or u'' which should be the
+18 −0
Original line number Diff line number Diff line
@@ -295,6 +295,24 @@ attribute in the Form gets precedence.
>>> print f['get_spam']
<input checked="checked" type="checkbox" name="get_spam" />

'True' or 'true' should be rendered without a value attribute
>>> f = SignupForm({'email': 'test@example.com', 'get_spam': 'True'}, auto_id=False)
>>> print f['get_spam']
<input checked="checked" type="checkbox" name="get_spam" />

>>> f = SignupForm({'email': 'test@example.com', 'get_spam': 'true'}, auto_id=False)
>>> print f['get_spam']
<input checked="checked" type="checkbox" name="get_spam" />

A value of 'False' or 'false' should be rendered unchecked
>>> f = SignupForm({'email': 'test@example.com', 'get_spam': 'False'}, auto_id=False)
>>> print f['get_spam']
<input type="checkbox" name="get_spam" />

>>> f = SignupForm({'email': 'test@example.com', 'get_spam': 'false'}, auto_id=False)
>>> print f['get_spam']
<input type="checkbox" name="get_spam" />

Any Field can have a Widget class passed to its constructor:
>>> class ContactForm(Form):
...     subject = CharField()