Skip to content

Commit 992f143

Browse files
kakulukiatimgraham
authored andcommitted
[1.11.x] Fixed #28278 -- Fixed invalid HTML for a required AdminFileWidget.
Backport of 525dc28 from master
1 parent 6ae6029 commit 992f143

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% if is_initial %}<p class="file-upload">{{ initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
22
<span class="clearable-file-input">
33
<input type="checkbox" name="{{ checkbox_name }}" id="{{ checkbox_id }}" />
4-
<label for="{{ checkbox_id }}">{{ clear_checkbox_label }}</label>{% endif %}</span><br />
4+
<label for="{{ checkbox_id }}">{{ clear_checkbox_label }}</label></span>{% endif %}<br />
55
{{ input_text }}:{% endif %}
66
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} />{% if is_initial %}</p>{% endif %}

docs/releases/1.11.3.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ Bugfixes
2121

2222
* Fixed admin's ``FieldListFilter.get_queryset()`` crash on invalid input
2323
(:ticket:`28202`).
24+
25+
* Fixed invalid HTML for a required ``AdminFileWidget`` (:ticket:`28278`).

tests/admin_widgets/tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,18 @@ def test_render(self):
434434
'<input type="file" name="test" />',
435435
)
436436

437+
def test_render_required(self):
438+
widget = widgets.AdminFileWidget()
439+
widget.is_required = True
440+
self.assertHTMLEqual(
441+
widget.render('test', self.album.cover_art),
442+
'<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
443+
r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a><br />'
444+
'Change: <input type="file" name="test" /></p>' % {
445+
'STORAGE_URL': default_storage.url(''),
446+
},
447+
)
448+
437449
def test_readonly_fields(self):
438450
"""
439451
File widgets should render as a link when they're marked "read only."

0 commit comments

Comments
 (0)