diff --git a/django/forms/fields.py b/django/forms/fields.py index 62d68985c073..4ec7b7aee74f 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -261,6 +261,10 @@ def __deepcopy__(self, memo): result.validators = self.validators[:] return result + def _clean_bound_field(self, bf): + value = bf.initial if self.disabled else bf.data + return self.clean(value) + class CharField(Field): def __init__( @@ -694,6 +698,10 @@ def bound_data(self, _, initial): def has_changed(self, initial, data): return not self.disabled and data is not None + def _clean_bound_field(self, bf): + value = bf.initial if self.disabled else bf.data + return self.clean(value, bf.initial) + class ImageField(FileField): default_validators = [validators.validate_image_file_extension] diff --git a/django/forms/forms.py b/django/forms/forms.py index 5de14d598af3..452f554e1eca 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -6,7 +6,7 @@ import datetime from django.core.exceptions import NON_FIELD_ERRORS, ValidationError -from django.forms.fields import Field, FileField +from django.forms.fields import Field from django.forms.utils import ErrorDict, ErrorList, RenderableFormMixin from django.forms.widgets import Media, MediaDefiningClass from django.utils.datastructures import MultiValueDict @@ -329,13 +329,8 @@ def full_clean(self): def _clean_fields(self): for name, bf in self._bound_items(): field = bf.field - value = bf.initial if field.disabled else bf.data try: - if isinstance(field, FileField): - value = field.clean(value, bf.initial) - else: - value = field.clean(value) - self.cleaned_data[name] = value + self.cleaned_data[name] = field._clean_bound_field(bf) if hasattr(self, "clean_%s" % name): value = getattr(self, "clean_%s" % name)() self.cleaned_data[name] = value