1
0
mirror of https://github.com/django/django.git synced 2025-01-03 15:06:09 +00:00

Refs #32819 -- Avoided adding 'aria-describedby' to hidden inputs.

Hidden elements are not visible for both accessibility tools and browsers presentation layer. This change therefore only reduces the size of the generated HTML.
This commit is contained in:
David Smith 2024-04-29 08:13:35 +01:00 committed by Sarah Boyce
parent 85c154da2f
commit c187f5f924
2 changed files with 10 additions and 0 deletions

View File

@ -298,6 +298,7 @@ class BoundField(RenderableFieldMixin):
and self.field.help_text and self.field.help_text
and not self.use_fieldset and not self.use_fieldset
and self.auto_id and self.auto_id
and not self.is_hidden
): ):
attrs["aria-describedby"] = f"{self.auto_id}_helptext" attrs["aria-describedby"] = f"{self.auto_id}_helptext"
return attrs return attrs

View File

@ -2136,6 +2136,15 @@ class FormsTestCase(SimpleTestCase):
p.as_p(), '<input type="hidden" name="foo"><input type="hidden" name="bar">' p.as_p(), '<input type="hidden" name="foo"><input type="hidden" name="bar">'
) )
def test_hidden_widget_does_not_have_aria_describedby(self):
class TestForm(Form):
hidden_text = CharField(widget=HiddenInput, help_text="Help Text")
f = TestForm()
self.assertEqual(
str(f), '<input type="hidden" name="hidden_text" id="id_hidden_text">'
)
def test_field_order(self): def test_field_order(self):
# A Form's fields are displayed in the same order in which they were defined. # A Form's fields are displayed in the same order in which they were defined.
class TestForm(Form): class TestForm(Form):