summaryrefslogtreecommitdiff
path: root/django/forms/widgets.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2016-08-12 10:59:01 -0700
committerTim Graham <timograham@gmail.com>2016-08-12 13:59:01 -0400
commitfab46ce6f5a0a58c4e5e39c9e5e412702beb4a64 (patch)
tree361730d067142bfc0e51ecfd2e65b9d719f08a07 /django/forms/widgets.py
parentf842d1011c1195aa26071a6ab6f96e0b8d907343 (diff)
Fixed #27037 -- Prevented required attribute on ClearableFileInput when initial data exists.
Diffstat (limited to 'django/forms/widgets.py')
-rw-r--r--django/forms/widgets.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 13d22672bf..d6b84c10ab 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -248,6 +248,9 @@ class Widget(six.with_metaclass(RenameWidgetMethods)):
"""
return id_
+ def use_required_attribute(self, initial):
+ return not self.is_hidden
+
class Input(Widget):
"""
@@ -429,6 +432,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):
@@ -795,12 +801,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):