mirror of https://github.com/django/django.git
Fixed #26129 -- Made invalid forms display initial values of disabled fields.
This commit is contained in:
parent
4b0118465b
commit
04564eb74d
|
@ -167,6 +167,8 @@ class Field(object):
|
||||||
For most fields, this will simply be data; FileFields need to handle it
|
For most fields, this will simply be data; FileFields need to handle it
|
||||||
a bit differently.
|
a bit differently.
|
||||||
"""
|
"""
|
||||||
|
if self.disabled:
|
||||||
|
return initial
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def widget_attrs(self, widget):
|
def widget_attrs(self, widget):
|
||||||
|
|
|
@ -91,3 +91,6 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed the ``contrib.gis`` map widgets when using
|
* Fixed the ``contrib.gis`` map widgets when using
|
||||||
``USE_THOUSAND_SEPARATOR=True`` (:ticket:`20415`).
|
``USE_THOUSAND_SEPARATOR=True`` (:ticket:`20415`).
|
||||||
|
|
||||||
|
* Made invalid forms display the initial of values of their disabled fields
|
||||||
|
(:ticket:`26129`).
|
||||||
|
|
|
@ -718,6 +718,14 @@ class FormsTestCase(SimpleTestCase):
|
||||||
{'birthday': datetime.date(1974, 8, 16), 'name': 'John Doe'}
|
{'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):
|
def test_hidden_data(self):
|
||||||
class SongForm(Form):
|
class SongForm(Form):
|
||||||
name = CharField()
|
name = CharField()
|
||||||
|
|
Loading…
Reference in New Issue