diff options
| author | Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com> | 2017-07-13 20:25:32 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-14 13:06:51 -0400 |
| commit | 5debbdfcc84266703191e084914998e38f5f52eb (patch) | |
| tree | 8595d4e155a38ead719dd958db1833aada4c54a4 /django/forms | |
| parent | 2e9ada15510e5729c331d7383fc9827e9082a8a9 (diff) | |
Fixed #28387 -- Fixed has_changed() for disabled form fields that subclass it.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/fields.py | 8 | ||||
| -rw-r--r-- | django/forms/models.py | 4 |
2 files changed, 12 insertions, 0 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 3a0609b915..ce4261cbf5 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -586,6 +586,8 @@ class FileField(Field): return data def has_changed(self, initial, data): + if self.disabled: + return False if data is None: return False return True @@ -706,6 +708,8 @@ class BooleanField(Field): raise ValidationError(self.error_messages['required'], code='required') def has_changed(self, initial, data): + if self.disabled: + return False # Sometimes data or initial may be a string equivalent of a boolean # so we should run it through to_python first to get a boolean value return self.to_python(initial) != self.to_python(data) @@ -864,6 +868,8 @@ class MultipleChoiceField(ChoiceField): ) def has_changed(self, initial, data): + if self.disabled: + return False if initial is None: initial = [] if data is None: @@ -1042,6 +1048,8 @@ class MultiValueField(Field): raise NotImplementedError('Subclasses must implement this method.') def has_changed(self, initial, data): + if self.disabled: + return False if initial is None: initial = ['' for x in range(0, len(data))] else: diff --git a/django/forms/models.py b/django/forms/models.py index b426623bce..37ef43b767 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -1250,6 +1250,8 @@ class ModelChoiceField(ChoiceField): return Field.validate(self, value) def has_changed(self, initial, data): + if self.disabled: + return False initial_value = initial if initial is not None else '' data_value = data if data is not None else '' return str(self.prepare_value(initial_value)) != str(data_value) @@ -1334,6 +1336,8 @@ class ModelMultipleChoiceField(ModelChoiceField): return super().prepare_value(value) def has_changed(self, initial, data): + if self.disabled: + return False if initial is None: initial = [] if data is None: |
