Skip to content

Commit

Permalink
Refs #32819 -- Avoided adding 'aria-describedby' to hidden inputs.
Browse files Browse the repository at this point in the history
Hidden elements are not visible for both accessibility tools and browsers presentation layer. This change therefore only reduces the size of the generated HTML.
  • Loading branch information
smithdc1 authored and sarahboyce committed Apr 30, 2024
1 parent 85c154d commit c187f5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions django/forms/boundfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def build_widget_attrs(self, attrs, widget=None):
and self.field.help_text
and not self.use_fieldset
and self.auto_id
and not self.is_hidden
):
attrs["aria-describedby"] = f"{self.auto_id}_helptext"
return attrs
Expand Down
9 changes: 9 additions & 0 deletions tests/forms_tests/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,15 @@ class TestForm(Form):
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):
# A Form's fields are displayed in the same order in which they were defined.
class TestForm(Form):
Expand Down

0 comments on commit c187f5f

Please sign in to comment.