From 9942f3fb490f56bf28ee69f0a07f3eb62e7d3ab3 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Wed, 24 Aug 2022 14:35:01 +0530 Subject: [PATCH] Fixed #33830 -- Fixed VariableDoesNotExist when rendering ClearableFileInput. --- django/forms/widgets.py | 1 + .../widget_tests/test_clearablefileinput.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 71f2710a2b5..96cb9102732 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -481,6 +481,7 @@ class ClearableFileInput(FileInput): "clear_checkbox_label": self.clear_checkbox_label, } ) + context["widget"]["attrs"].setdefault("disabled", False) return context def value_from_datadict(self, data, files, name): diff --git a/tests/forms_tests/widget_tests/test_clearablefileinput.py b/tests/forms_tests/widget_tests/test_clearablefileinput.py index fb6a2f6b72c..4fbaec0910c 100644 --- a/tests/forms_tests/widget_tests/test_clearablefileinput.py +++ b/tests/forms_tests/widget_tests/test_clearablefileinput.py @@ -110,6 +110,16 @@ class ClearableFileInputTest(WidgetTest): ), ) + def test_render_no_disabled(self): + class TestForm(Form): + clearable_file = FileField( + widget=self.widget, initial=FakeFieldFile(), required=False + ) + + form = TestForm() + with self.assertNoLogs("django.template", "DEBUG"): + form.render() + def test_render_as_subwidget(self): """A ClearableFileInput as a subwidget of MultiWidget.""" widget = MultiWidget(widgets=(self.widget,))