[1.10.x] Fixed #27037 -- Prevented required attribute on ClearableFileInput when initial data exists.

Backport of fab46ce6f5 from master
This commit is contained in:
Jon Dufresne 2016-08-12 10:59:01 -07:00 committed by Tim Graham
parent 13fd711f10
commit d8cda352b1
8 changed files with 66 additions and 18 deletions

View file

@ -249,6 +249,9 @@ class Widget(six.with_metaclass(RenameWidgetMethods)):
"""
return id_
def use_required_attribute(self, initial):
return not self.is_hidden
class Input(Widget):
"""
@ -428,6 +431,9 @@ class ClearableFileInput(FileInput):
return False
return upload
def use_required_attribute(self, initial):
return super(ClearableFileInput, self).use_required_attribute(initial) and not initial
class Textarea(Widget):
def __init__(self, attrs=None):
@ -790,12 +796,10 @@ class CheckboxSelectMultiple(RendererMixin, SelectMultiple):
renderer = CheckboxFieldRenderer
_empty_value = []
def build_attrs(self, extra_attrs=None, **kwargs):
attrs = super(CheckboxSelectMultiple, self).build_attrs(extra_attrs, **kwargs)
# Remove the 'required' attribute because browser validation would
def use_required_attribute(self, initial):
# Don't use the 'required' attribute because browser validation would
# require all checkboxes to be checked instead of at least one.
attrs.pop('required', None)
return attrs
return False
class MultiWidget(Widget):