diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index d56fa0ea3e..d0d5c13b3d 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -298,6 +298,7 @@ class BoundField(RenderableFieldMixin): 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 diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index a86d443e33..3982cc93fe 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -2136,6 +2136,15 @@ class FormsTestCase(SimpleTestCase): p.as_p(), '' ) + 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), '' + ) + def test_field_order(self): # A Form's fields are displayed in the same order in which they were defined. class TestForm(Form):