mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #31536 -- Fixed rendering of disabled AdminFileWidget and ClearableFileInput.
This commit is contained in:
parent
578b3046e3
commit
e46c2326c8
@ -1,6 +1,6 @@
|
||||
{% if widget.is_initial %}<p class="file-upload">{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
|
||||
<span class="clearable-file-input">
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}">
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"{% if widget.attrs.disabled %} disabled{% endif %}>
|
||||
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label></span>{% endif %}<br>
|
||||
{{ widget.input_text }}:{% endif %}
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% if widget.is_initial %}</p>{% endif %}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}">
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"{% if widget.attrs.disabled %} disabled{% endif %}>
|
||||
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br>
|
||||
{{ widget.input_text }}:{% endif %}
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}">
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"{% if widget.attrs.disabled %} disabled{% endif %}>
|
||||
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br>
|
||||
{{ widget.input_text }}:{% endif %}
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
|
||||
|
@ -487,6 +487,20 @@ class AdminFileWidgetTests(TestDataMixin, TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_render_disabled(self):
|
||||
widget = widgets.AdminFileWidget(attrs={'disabled': True})
|
||||
self.assertHTMLEqual(
|
||||
widget.render('test', self.album.cover_art),
|
||||
'<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
|
||||
r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> '
|
||||
'<span class="clearable-file-input">'
|
||||
'<input type="checkbox" name="test-clear" id="test-clear_id" disabled>'
|
||||
'<label for="test-clear_id">Clear</label></span><br>'
|
||||
'Change: <input type="file" name="test" disabled></p>' % {
|
||||
'STORAGE_URL': default_storage.url(''),
|
||||
},
|
||||
)
|
||||
|
||||
def test_readonly_fields(self):
|
||||
"""
|
||||
File widgets should render as a link when they're marked "read only."
|
||||
|
@ -74,6 +74,21 @@ class ClearableFileInputTest(WidgetTest):
|
||||
"""
|
||||
self.check_html(self.widget, 'myfile', None, html='<input type="file" name="myfile">')
|
||||
|
||||
def test_render_disabled(self):
|
||||
self.check_html(
|
||||
self.widget,
|
||||
'myfile',
|
||||
FakeFieldFile(),
|
||||
attrs={'disabled': True},
|
||||
html=(
|
||||
'Currently: <a href="something">something</a>'
|
||||
'<input type="checkbox" name="myfile-clear" '
|
||||
'id="myfile-clear_id" disabled>'
|
||||
'<label for="myfile-clear_id">Clear</label><br>'
|
||||
'Change: <input type="file" name="myfile" disabled>'
|
||||
),
|
||||
)
|
||||
|
||||
def test_render_as_subwidget(self):
|
||||
"""A ClearableFileInput as a subwidget of MultiWidget."""
|
||||
widget = MultiWidget(widgets=(self.widget,))
|
||||
|
Loading…
Reference in New Issue
Block a user