Skip to content

Commit

Permalink
[1.5.x] Fixed #19537 -- Made CheckboxInput._has_changed handle 'False…
Browse files Browse the repository at this point in the history
…' string

Thanks dibrovsd@gmail.com for the report.
Backport of d11038a from master.
  • Loading branch information
claudep committed Dec 31, 2012
1 parent fa71536 commit 814c3b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions django/forms/widgets.py
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/regressiontests/forms/tests/widgets.py
Expand Up @@ -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()
Expand Down

0 comments on commit 814c3b2

Please sign in to comment.