diff options
| author | Tim Graham <timograham@gmail.com> | 2016-01-28 13:49:51 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-29 08:08:04 -0500 |
| commit | 01db3249e5048093c85de33e5395ba737d330d0a (patch) | |
| tree | e822ced2960ccadfc0e3d29882e6f56ae46b56de | |
| parent | efd855481581b5758d866a009bbd1074e74869b4 (diff) | |
[1.9.x] Fixed #26129 -- Made invalid forms display initial values of disabled fields.
Backport of 04564eb74d2d92eaf88b22ab8cec7ef45978111e from master
| -rw-r--r-- | django/forms/fields.py | 2 | ||||
| -rw-r--r-- | docs/releases/1.9.2.txt | 3 | ||||
| -rw-r--r-- | tests/forms_tests/tests/test_forms.py | 8 |
3 files changed, 13 insertions, 0 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index d2ae133486..e59cf81890 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -177,6 +177,8 @@ class Field(six.with_metaclass(RenameFieldMethods, object)): For most fields, this will simply be data; FileFields need to handle it a bit differently. """ + if self.disabled: + return initial return data def widget_attrs(self, widget): diff --git a/docs/releases/1.9.2.txt b/docs/releases/1.9.2.txt index 6535fff099..cfa04b703f 100644 --- a/docs/releases/1.9.2.txt +++ b/docs/releases/1.9.2.txt @@ -91,3 +91,6 @@ Bugfixes * Fixed the ``contrib.gis`` map widgets when using ``USE_THOUSAND_SEPARATOR=True`` (:ticket:`20415`). + +* Made invalid forms display the initial of values of their disabled fields + (:ticket:`26129`). diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 917b5c99d2..00d2045786 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -718,6 +718,14 @@ class FormsTestCase(SimpleTestCase): {'birthday': datetime.date(1974, 8, 16), 'name': 'John Doe'} ) + # Initial data remains present on invalid forms. + data = {} + f1 = PersonForm(data, initial={'birthday': datetime.date(1974, 8, 16)}) + f2 = PersonFormFieldInitial(data) + for form in (f1, f2): + self.assertFalse(form.is_valid()) + self.assertEqual(form['birthday'].value(), datetime.date(1974, 8, 16)) + def test_hidden_data(self): class SongForm(Form): name = CharField() |
