Ticket #17114: 17114.diff

File 17114.diff, 1.4 KB (added by Preston Holmes, 13 years ago)
  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 5b50f37..57334f8 100644
    a b class CheckboxInput(Widget):  
    478478            result = False
    479479        if result:
    480480            final_attrs['checked'] = 'checked'
    481         if value not in ('', True, False, None):
     481        if value is 1 or value not in ('', True, False, None):
    482482            # Only add the 'value' attribute if a value is non-empty.
    483483            final_attrs['value'] = force_unicode(value)
    484484        return mark_safe(u'<input%s />' % flatatt(final_attrs))
  • tests/regressiontests/forms/tests/widgets.py

    diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
    index 2424bea..e84d1fe 100644
    a b class FormsWidgetTestCase(TestCase):  
    188188        self.assertEqual(w.render('is_cool', None), u'<input type="checkbox" name="is_cool" />')
    189189        self.assertEqual(w.render('is_cool', False), u'<input type="checkbox" name="is_cool" />')
    190190        self.assertEqual(w.render('is_cool', True), u'<input checked="checked" type="checkbox" name="is_cool" />')
     191        self.assertEqual(w.render('is_cool', 1), u'<input checked="checked" type="checkbox" name="is_cool" value="1" />')
    191192
    192193        # Using any value that's not in ('', None, False, True) will check the checkbox
    193194        # and set the 'value' attribute.
Back to Top