summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Veldman <veldman@gw20e.com>2016-11-06 10:30:48 +0100
committerTim Graham <timograham@gmail.com>2016-11-11 06:57:57 -0500
commit8618a7eaa16bf11f41dd850b42858381f850ce0e (patch)
treebcf4c531b6809af87feb1100855ea059cb81c609
parent7b05ffd95d2ab8c6653ce4efc49658efb79965c8 (diff)
Fixed #27431 -- Prevented disabled form fields from appearing as changed.
-rw-r--r--django/forms/fields.py4
-rw-r--r--tests/forms_tests/field_tests/test_base.py6
2 files changed, 10 insertions, 0 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index d9552c28fe..74cc3a6552 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -187,6 +187,10 @@ class Field(object):
"""
Return True if data differs from initial.
"""
+ # Always return False if the field is disabled since self.bound_data
+ # always uses the initial value in this case.
+ if self.disabled:
+ return False
try:
data = self.to_python(data)
if hasattr(self, '_coerce'):
diff --git a/tests/forms_tests/field_tests/test_base.py b/tests/forms_tests/field_tests/test_base.py
index 802af3b183..67c3003393 100644
--- a/tests/forms_tests/field_tests/test_base.py
+++ b/tests/forms_tests/field_tests/test_base.py
@@ -34,3 +34,9 @@ class BasicFieldsTests(SimpleTestCase):
f.fields['field2'].choices = [('2', '2')]
self.assertEqual(f.fields['field1'].widget.choices, [('1', '1')])
self.assertEqual(f.fields['field2'].widget.choices, [('2', '2')])
+
+
+class DisabledFieldTests(SimpleTestCase):
+ def test_disabled_field_has_changed_always_false(self):
+ disabled_field = Field(disabled=True)
+ self.assertFalse(disabled_field.has_changed('x', 'y'))