From eec7e9ba894a7815d289ba7446eeead488fe0e33 Mon Sep 17 00:00:00 2001 From: David Smith Date: Sun, 12 Nov 2023 17:24:16 +0000 Subject: Refs #32819 -- Established relationship between form fieldsets and their help text. This adds aria-describedby for widgets rendered in a fieldset such as radios. aria-describedby for these widgets is added to the
element rather than each . --- tests/forms_tests/tests/test_forms.py | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'tests/forms_tests') 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: A' + "
" + '' + "
" + '
' + "Radio:" + '
Radio help text
' + '
' + '' + "
" + '' + "
" + '
' + "Datetime:" + '
Enter Date and Time
' + '' + '' + "
", + ) + f = FieldsetForm(auto_id=False) + # aria-describedby is not included. + self.assertIn("
", str(f)) + self.assertIn('
', 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('
', 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
. + 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), + "
Checkbox:" + '
Checkbox help text
' + '
' + '' + "
" + '' + "
", + ) + def test_as_widget_custom_aria_describedby(self): class FoodForm(Form): intl_name = CharField(help_text="The food's international name.") -- cgit v1.3