Skip to content

Commit

Permalink
Fix "disabled" parameter for RadioSelect and CheckboxSelectMultiple (#…
Browse files Browse the repository at this point in the history
…164)

* Fix "disabled" parameter for RadioSelect and CheckboxSelectMultiple

* Add test, remove debug print statement

* Remove obsolete code

* Update CHANGELOG and prepare release

Co-authored-by: Sven Hertle <hertle@narfi.net>
  • Loading branch information
dyve and svenhertle committed Aug 16, 2021
1 parent 5e405ef commit 9e07cde
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## [2.1.2] - 2021-08-16

- Fix disabled parameter for RadioSelect and CheckboxSelectMultiple (#163).

## [2.1.1] - 2021-07-11

- Respect safe strings in bootstrap_messages (#145).
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@
setup(
name="django-bootstrap5",
zip_safe=False,
version="2.1.1",
version="2.1.2",
description="Bootstrap 5 for Django",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
Expand Up @@ -11,7 +11,8 @@
name="{{ option.name }}"
id="{{ option.attrs.id }}"
{% if option.value != None %} value="{{ option.value|stringformat:'s' }}"
{% if option.attrs.checked %} checked="checked"{% endif %}{% endif %}>
{% if option.attrs.checked %} checked="checked"{% endif %}{% endif %}
{% if widget.attrs.disabled %} disabled{% endif %}>
<label class="form-check-label" for="{{ option.attrs.id }}">{{ option.label }}</label>
</div>
{% endfor %}
Expand Down
33 changes: 33 additions & 0 deletions tests/test_bootstrap_field_radio_select.py
Expand Up @@ -13,6 +13,17 @@ class SelectTestForm(forms.Form):
)


class DisabledSelectTestForm(forms.Form):
test = forms.ChoiceField(
choices=(
(1, "one"),
(2, "two"),
),
widget=forms.RadioSelect,
disabled=True,
)


class BootstrapFieldSelectTestCase(BootstrapTestCase):
def test_select(self):
"""Test field with select widget."""
Expand Down Expand Up @@ -78,3 +89,25 @@ def test_select_floating(self):
"</div>"
),
)

def test_disabled_select(self):
"""Test field with disabled select widget."""
self.maxDiff = None
self.assertHTMLEqual(
self.render("{% bootstrap_field form.test %}", context={"form": DisabledSelectTestForm()}),
(
'<div class="django_bootstrap5-req mb-3">'
'<label class="form-label" for="id_test_0">Test</label>'
'<div class="" disabled required id="id_test">'
'<div class="form-check">'
'<input class="form-check-input" disabled type="radio" name="test" id="id_test_0" value="1">'
'<label class="form-check-label" for="id_test_0">one</label>'
"</div>"
'<div class="form-check">'
'<input class="form-check-input" disabled type="radio" name="test" id="id_test_1" value="2">'
'<label class="form-check-label" for="id_test_1">two</label>'
"</div>"
"</div>"
"</div>"
),
)
2 changes: 0 additions & 2 deletions tests/test_bootstrap_messages.py
Expand Up @@ -54,8 +54,6 @@ def test_bootstrap_messages_with_other_content(self):

def test_bootstrap_messages_with_safe_message(self):
messages = [Message(DEFAULT_MESSAGE_LEVELS.INFO, mark_safe("Click <a href='https://www.github.com/'>here</a>"))]
html = self.render("{% bootstrap_messages messages %}", {"messages": messages})
print(html)
self.assertHTMLEqual(
self.render("{% bootstrap_messages messages %}", {"messages": messages}),
self._html(content="Click <a href='https://www.github.com/'>here</a>", css_class="alert-info"),
Expand Down

0 comments on commit 9e07cde

Please sign in to comment.