summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-12-31 10:18:59 +0100
committerClaude Paroz <claude@2xlibre.net>2012-12-31 10:24:48 +0100
commit814c3b2e2a8da001af38f679ed2334239150a975 (patch)
tree91fc5ffc63b58498147857bc8f0293e7cd30df4c
parentfa7153612999191323a206b8bf478f6a78d55073 (diff)
[1.5.x] Fixed #19537 -- Made CheckboxInput._has_changed handle 'False' string
Thanks dibrovsd@gmail.com for the report. Backport of d11038acb2 from master.
-rw-r--r--django/forms/widgets.py3
-rw-r--r--tests/regressiontests/forms/tests/widgets.py2
2 files changed, 5 insertions, 0 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index c761ea857d..4782b99117 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -533,6 +533,9 @@ class CheckboxInput(Widget):
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):
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
index 31c0e65c7c..f9dc4a7ec8 100644
--- a/tests/regressiontests/forms/tests/widgets.py
+++ b/tests/regressiontests/forms/tests/widgets.py
@@ -240,6 +240,8 @@ class FormsWidgetTestCase(TestCase):
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()