diff --git a/crispy_tailwind/templates/tailwind/layout/select.html b/crispy_tailwind/templates/tailwind/layout/select.html index ae784f5..fef34ac 100644 --- a/crispy_tailwind/templates/tailwind/layout/select.html +++ b/crispy_tailwind/templates/tailwind/layout/select.html @@ -4,7 +4,7 @@
diff --git a/crispy_tailwind/templates/tailwind/layout/select_option.html b/crispy_tailwind/templates/tailwind/layout/select_option.html index 2f4364f..afb5a31 100644 --- a/crispy_tailwind/templates/tailwind/layout/select_option.html +++ b/crispy_tailwind/templates/tailwind/layout/select_option.html @@ -1,4 +1,4 @@ {% load crispy_forms_filters %} {% load l10n %} - + diff --git a/tests/forms.py b/tests/forms.py index f317e78..0a4753f 100644 --- a/tests/forms.py +++ b/tests/forms.py @@ -63,3 +63,11 @@ class SelectForm(forms.Form): widget=forms.Select(), choices=(("accepted", "Accepted"), ("not_accepted", "Not accepted")), ) + + +class AgeRangeSelectForm(forms.Form): + age_range = forms.ChoiceField( + label="age range", + widget=forms.Select(), + choices=((0, "18-24"), (1, "25-44"), (2, "45+")), + ) diff --git a/tests/test_helper.py b/tests/test_helper.py index b141bb1..730ac12 100644 --- a/tests/test_helper.py +++ b/tests/test_helper.py @@ -9,6 +9,7 @@ from crispy_tailwind.layout import Button, Reset, Submit from .forms import ( + AgeRangeSelectForm, CharFieldForm, CheckboxMultiple, PasswordFieldForm, @@ -572,3 +573,27 @@ def test_select(self):
""" self.assertHTMLEqual(html, expected_html) + + def test_select_option_preserved_on_bound_forms(self): + form = AgeRangeSelectForm(data={"age_range": 1}) + form.helper = FormHelper() + form.helper.form_tag = False + html = render_crispy_form(form) + expected_html = """ +
+ +
+
+ +
+ +
+
+
+
+ """ + self.assertHTMLEqual(html, expected_html)