Browse files

Fixed #19537 -- Made CheckboxInput._has_changed handle 'False' string

Thanks dibrovsd@gmail.com for the report.
  • Loading branch information...
1 parent cee40c7 commit d11038acb2ea2f59a1d00a41b553f578b5f2c59c @claudep claudep committed Dec 31, 2012
Showing with 5 additions and 0 deletions.
  1. +3 −0 django/forms/widgets.py
  2. +2 −0 tests/regressiontests/forms/tests/widgets.py
View
3 django/forms/widgets.py
@@ -533,6 +533,9 @@ def value_from_datadict(self, data, files, name):
def _has_changed(self, initial, data):
# Sometimes data or initial could be None or '' which should be the
# same thing as False.
+ if initial == 'False':
+ # show_hidden_initial may have transformed False to 'False'
+ initial = False
return bool(initial) != bool(data)
class Select(Widget):
View
2 tests/regressiontests/forms/tests/widgets.py
@@ -240,6 +240,8 @@ def test_checkboxinput(self):
self.assertTrue(w._has_changed(False, 'on'))
self.assertFalse(w._has_changed(True, 'on'))
self.assertTrue(w._has_changed(True, ''))
+ # Initial value may have mutated to a string due to show_hidden_initial (#19537)
+ self.assertTrue(w._has_changed('False', 'on'))
def test_select(self):
w = Select()

0 comments on commit d11038a

Please sign in to comment.