Fixed #27805 -- Fixed ClearableFileInput's "Clear" checkbox on model fields with a default.
This commit is contained in:
parent
7c4289d0b9
commit
4353640ea9
|
@ -420,6 +420,12 @@ class ClearableFileInput(FileInput):
|
|||
def use_required_attribute(self, initial):
|
||||
return super().use_required_attribute(initial) and not initial
|
||||
|
||||
def value_omitted_from_data(self, data, files, name):
|
||||
return (
|
||||
super().value_omitted_from_data(data, files, name) and
|
||||
self.clear_checkbox_name(name) not in data
|
||||
)
|
||||
|
||||
|
||||
class Textarea(Widget):
|
||||
template_name = 'django/forms/widgets/textarea.html'
|
||||
|
|
|
@ -9,4 +9,5 @@ Django 1.10.6 fixes several bugs in 1.10.5.
|
|||
Bugfixes
|
||||
========
|
||||
|
||||
* ...
|
||||
* Fixed ``ClearableFileInput``’s "Clear" checkbox on model form fields where
|
||||
the model field has a ``default`` (:ticket:`27805`).
|
||||
|
|
|
@ -143,3 +143,9 @@ class ClearableFileInputTest(WidgetTest):
|
|||
# user to keep the existing, initial value.
|
||||
self.assertIs(self.widget.use_required_attribute(None), True)
|
||||
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