mirror of
https://github.com/django/django.git
synced 2025-07-23 05:05:17 +00:00
[1.10.x] Fixed #27037 -- Prevented required attribute on ClearableFileInput when initial data exists.
Backport of fab46ce6f5
from master
This commit is contained in:
parent
13fd711f10
commit
d8cda352b1
8 changed files with 66 additions and 18 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue