Skip to content
/ django Public

Commit b7b5465

Browse files
codingjoejacobtylerwalls
authored andcommitted
[6.0.x] Fixed #36829 -- Reverted value of ClearableFileInput.use_fieldset to True.
There was unresolved discussion regarding whether to set ClearableFileInput.use_fieldset to True or False when use_fieldset was introduced in Django 4.1, since the clear checkbox appears only sometimes. Although using <fieldset> is likely desirable, since the primary motivation in #35892 was just to improve markup in the admin, and a deprecation path was not provided for general form usage, future work is deferred to #36828. Regression in 4187da2. Thanks Tim Graham, Antoliny, and David Smith for triage.
1 parent 90daa65 commit b7b5465

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

django/contrib/admin/widgets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class AdminRadioSelect(forms.RadioSelect):
122122

123123
class AdminFileWidget(forms.ClearableFileInput):
124124
template_name = "admin/widgets/clearable_file_input.html"
125+
use_fieldset = True
125126

126127

127128
def url_params_from_lookup_dict(lookups):

django/forms/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class ClearableFileInput(FileInput):
530530
input_text = _("Change")
531531
template_name = "django/forms/widgets/clearable_file_input.html"
532532
checked = False
533-
use_fieldset = True
533+
use_fieldset = False
534534

535535
def clear_checkbox_name(self, name):
536536
"""

docs/releases/6.0.1.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ Bugfixes
3535
* Fixed a regression in Django 6.0 where :func:`~django.urls.path` routes
3636
defined using :func:`~django.utils.translation.gettext_lazy` failed to
3737
resolve correctly (:ticket:`36796`).
38+
39+
* Fixed a regression in Django 6.0 where the :attr:`.Widget.use_fieldset`
40+
attribute of :class:`~django.forms.ClearableFileInput` was flipped
41+
from ``False`` to ``True`` (:ticket:`36829`).

tests/forms_tests/widget_tests/test_clearablefileinput.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,18 @@ class TestForm(Form):
246246
)
247247

248248
form = TestForm()
249-
self.assertIs(self.widget.use_fieldset, True)
249+
self.assertIs(self.widget.use_fieldset, False)
250250
self.assertHTMLEqual(
251-
'<div><fieldset><legend for="id_field">Field:</legend>'
252-
'<input id="id_field" name="field" type="file" required></fieldset></div>'
253-
'<div><fieldset><legend for="id_with_file">With file:</legend>Currently: '
251+
'<div><label for="id_field">Field:</label>'
252+
'<input id="id_field" name="field" type="file" required></div>'
253+
'<div><label for="id_with_file">With file:</label>Currently: '
254254
'<a href="something">something</a><br>Change:<input type="file" '
255-
'name="with_file" id="id_with_file"></fieldset></div>'
256-
'<div><fieldset><legend for="id_clearable_file">Clearable file:</legend>'
255+
'name="with_file" id="id_with_file"></div>'
256+
'<div><label for="id_clearable_file">Clearable file:</label>'
257257
'Currently: <a href="something">something</a><input '
258258
'type="checkbox" name="clearable_file-clear" id="clearable_file-clear_id">'
259259
'<label for="clearable_file-clear_id">Clear</label><br>Change:'
260-
'<input type="file" name="clearable_file" id="id_clearable_file">'
261-
"</fieldset></div>",
260+
'<input type="file" name="clearable_file" id="id_clearable_file"></div>',
262261
form.render(),
263262
)
264263

0 commit comments

Comments
 (0)