[1.11.x] Fixed #27805 -- Fixed ClearableFileInput's "Clear" checkbox on model fields with a default.
Backport of 4353640ea9
from master
This commit is contained in:
parent
f14899412d
commit
2b17e4770b
|
@ -437,6 +437,12 @@ class ClearableFileInput(FileInput):
|
||||||
def use_required_attribute(self, initial):
|
def use_required_attribute(self, initial):
|
||||||
return super(ClearableFileInput, self).use_required_attribute(initial) and not initial
|
return super(ClearableFileInput, self).use_required_attribute(initial) and not initial
|
||||||
|
|
||||||
|
def value_omitted_from_data(self, data, files, name):
|
||||||
|
return (
|
||||||
|
super(ClearableFileInput, self).value_omitted_from_data(data, files, name) and
|
||||||
|
self.clear_checkbox_name(name) not in data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Textarea(Widget):
|
class Textarea(Widget):
|
||||||
template_name = 'django/forms/widgets/textarea.html'
|
template_name = 'django/forms/widgets/textarea.html'
|
||||||
|
|
|
@ -9,4 +9,5 @@ Django 1.10.6 fixes several bugs in 1.10.5.
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed ``ClearableFileInput``’s "Clear" checkbox on model form fields where
|
||||||
|
the model field has a ``default`` (:ticket:`27805`).
|
||||||
|
|
|
@ -149,3 +149,9 @@ class ClearableFileInputTest(WidgetTest):
|
||||||
# user to keep the existing, initial value.
|
# user to keep the existing, initial value.
|
||||||
self.assertIs(self.widget.use_required_attribute(None), True)
|
self.assertIs(self.widget.use_required_attribute(None), True)
|
||||||
self.assertIs(self.widget.use_required_attribute('resume.txt'), False)
|
self.assertIs(self.widget.use_required_attribute('resume.txt'), False)
|
||||||
|
|
||||||
|
def test_value_omitted_from_data(self):
|
||||||
|
widget = ClearableFileInput()
|
||||||
|
self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
|
||||||
|
self.assertIs(widget.value_omitted_from_data({}, {'field': 'x'}, 'field'), False)
|
||||||
|
self.assertIs(widget.value_omitted_from_data({'field-clear': 'y'}, {}, 'field'), False)
|
||||||
|
|
Loading…
Reference in New Issue