Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.5.x] Fixed #19537 -- Made CheckboxInput._has_changed handle 'False…

…' string

Thanks dibrovsd@gmail.com for the report.
Backport of d11038a from master.
  • Loading branch information...
commit 814c3b2e2a8da001af38f679ed2334239150a975 1 parent fa71536
Claude Paroz claudep authored
3  django/forms/widgets.py
View
@@ -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):
2  tests/regressiontests/forms/tests/widgets.py
View
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.