Skip to content

Commit

Permalink
Fix CheckboxSelectMultiple on Django>4 (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
heso authored Jan 23, 2024
1 parent 01de534 commit 72588fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/bootstrap4/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ def fix_file_input_label(self, html):
return html

def post_widget_render(self, html):
if isinstance(self.widget, RadioSelect):
html = self.list_to_class(html, "radio radio-success")
elif isinstance(self.widget, CheckboxSelectMultiple):
if isinstance(self.widget, CheckboxSelectMultiple):
html = self.list_to_class(html, "checkbox")
elif isinstance(self.widget, RadioSelect):
html = self.list_to_class(html, "radio radio-success")
elif isinstance(self.widget, SelectDateWidget):
html = self.fix_date_select_input(html)
elif isinstance(self.widget, CheckboxInput):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ def test_checkbox(self):
self.assertIn("form-text", help_text["class"], "The help text should have the class 'form-text'.")
self.assertIn("text-muted", help_text["class"], "The help text should have the class 'text-muted'.")

def test_checkbox_multiple_select(self):
res = render_form_field("category2")
expected_html = (
'<div class="form-group bootstrap4-req">'
'<label>Category2</label>'
'<div class="checkbox" id="id_category2">'
'<div class="form-check">'
'<label class="form-check-label" for="id_category2_0">'
'<input class="form-check-input" id="id_category2_0" name="category2" title="Check as many as you like." type="checkbox" value="1">'
"Radio 1"
"</label>"
"</div>"
'<div class="form-check">'
'<label class="form-check-label" for="id_category2_1">'
'<input class="form-check-input" id="id_category2_1" name="category2" title="Check as many as you like." type="checkbox" value="2">'
"Radio 2"
"</label>"
"</div>"
"</div>"
'<small class="form-text text-muted">Check as many as you like.</small>'
"</div>"
)
self.assertHTMLEqual(res, expected_html)

def test_required_field(self):
required_css_class = "bootstrap4-req"
required_field = render_form_field("subject")
Expand Down

0 comments on commit 72588fe

Please sign in to comment.