summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_forms.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 7ea88f0cc8..19ca978c45 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -3114,6 +3114,83 @@ Options: <select multiple name="options" aria-invalid="true" required>
'required aria-describedby="id_username_helptext"></div>',
)
+ def test_fieldset_aria_describedby(self):
+ class FieldsetForm(Form):
+ checkbox = MultipleChoiceField(
+ choices=[("a", "A"), ("b", "B")],
+ widget=CheckboxSelectMultiple,
+ help_text="Checkbox help text",
+ )
+ radio = MultipleChoiceField(
+ choices=[("a", "A"), ("b", "B")],
+ widget=RadioSelect,
+ help_text="Radio help text",
+ )
+ datetime = SplitDateTimeField(help_text="Enter Date and Time")
+
+ f = FieldsetForm()
+ self.assertHTMLEqual(
+ str(f),
+ '<div><fieldset aria-describedby="id_checkbox_helptext">'
+ "<legend>Checkbox:</legend>"
+ '<div class="helptext" id="id_checkbox_helptext">Checkbox help text</div>'
+ '<div id="id_checkbox"><div>'
+ '<label for="id_checkbox_0"><input type="checkbox" name="checkbox" '
+ 'value="a" id="id_checkbox_0" /> A</label>'
+ "</div><div>"
+ '<label for="id_checkbox_1"><input type="checkbox" name="checkbox" '
+ 'value="b" id="id_checkbox_1" /> B</label>'
+ "</div></div></fieldset></div>"
+ '<div><fieldset aria-describedby="id_radio_helptext">'
+ "<legend>Radio:</legend>"
+ '<div class="helptext" id="id_radio_helptext">Radio help text</div>'
+ '<div id="id_radio"><div>'
+ '<label for="id_radio_0"><input type="radio" name="radio" value="a" '
+ 'required id="id_radio_0" />A</label>'
+ "</div><div>"
+ '<label for="id_radio_1"><input type="radio" name="radio" value="b" '
+ 'required id="id_radio_1" /> B</label>'
+ "</div></div></fieldset></div>"
+ '<div><fieldset aria-describedby="id_datetime_helptext">'
+ "<legend>Datetime:</legend>"
+ '<div class="helptext" id="id_datetime_helptext">Enter Date and Time</div>'
+ '<input type="text" name="datetime_0" required id="id_datetime_0" />'
+ '<input type="text" name="datetime_1" required id="id_datetime_1" />'
+ "</fieldset></div>",
+ )
+ f = FieldsetForm(auto_id=False)
+ # aria-describedby is not included.
+ self.assertIn("<fieldset>", str(f))
+ self.assertIn('<div class="helptext">', str(f))
+ f = FieldsetForm(auto_id="custom_%s")
+ # aria-describedby uses custom auto_id.
+ self.assertIn('fieldset aria-describedby="custom_checkbox_helptext"', str(f))
+ self.assertIn('<div class="helptext" id="custom_checkbox_helptext">', str(f))
+
+ def test_fieldset_custom_aria_describedby(self):
+ # aria-describedby set on widget results in aria-describedby being
+ # added to widget and not the <fieldset>.
+ class FieldsetForm(Form):
+ checkbox = MultipleChoiceField(
+ choices=[("a", "A"), ("b", "B")],
+ widget=CheckboxSelectMultiple(attrs={"aria-describedby": "custom-id"}),
+ help_text="Checkbox help text",
+ )
+
+ f = FieldsetForm()
+ self.assertHTMLEqual(
+ str(f),
+ "<div><fieldset><legend>Checkbox:</legend>"
+ '<div class="helptext" id="id_checkbox_helptext">Checkbox help text</div>'
+ '<div id="id_checkbox"><div>'
+ '<label for="id_checkbox_0"><input type="checkbox" name="checkbox" '
+ 'value="a" aria-describedby="custom-id" id="id_checkbox_0" />A</label>'
+ "</div><div>"
+ '<label for="id_checkbox_1"><input type="checkbox" name="checkbox" '
+ 'value="b" aria-describedby="custom-id" id="id_checkbox_1" />B</label>'
+ "</div></div></fieldset></div>",
+ )
+
def test_as_widget_custom_aria_describedby(self):
class FoodForm(Form):
intl_name = CharField(help_text="The food's international name.")