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:27:30 -0400 |
| commit | a3b5df8ed503ea559d2ffaca7ec0c735d98f1a38 (patch) | |
| tree | 3430d666d9322066f49390ce2a54501d485ef39c /django | |
| parent | fc6b90bdb7a9531e988245942f79518308616b7b (diff) | |
[1.11.x] Fixed #28387 -- Fixed has_changed() for disabled form fields that subclass it.
Backport of 5debbdfcc84266703191e084914998e38f5f52eb from master
Diffstat (limited to 'django')
| -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 33ed2882a3..f2b5b77185 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -604,6 +604,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 @@ -724,6 +726,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) @@ -891,6 +895,8 @@ class MultipleChoiceField(ChoiceField): ) def has_changed(self, initial, data): + if self.disabled: + return False if initial is None: initial = [] if data is None: @@ -1069,6 +1075,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 132e4255bb..db710a2ed2 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -1244,6 +1244,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 force_text(self.prepare_value(initial_value)) != force_text(data_value) @@ -1331,6 +1333,8 @@ class ModelMultipleChoiceField(ModelChoiceField): return super(ModelMultipleChoiceField, self).prepare_value(value) def has_changed(self, initial, data): + if self.disabled: + return False if initial is None: initial = [] if data is None: |
