diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index 39b0aaf97b..deba739329 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -287,6 +287,13 @@ class BoundField(RenderableFieldMixin): attrs["required"] = True if self.field.disabled: attrs["disabled"] = True + # If a custom aria-describedby attribute is given and help_text is + # used, the custom aria-described by is preserved so user can set the + # desired order. + if custom_aria_described_by_id := widget.attrs.get("aria-describedby"): + attrs["aria-describedby"] = custom_aria_described_by_id + elif self.field.help_text and self.id_for_label: + attrs["aria-describedby"] = f"{self.id_for_label}_helptext" return attrs @property diff --git a/django/forms/jinja2/django/forms/field.html b/django/forms/jinja2/django/forms/field.html index 56ffa1ad83..c8943d9481 100644 --- a/django/forms/jinja2/django/forms/field.html +++ b/django/forms/jinja2/django/forms/field.html @@ -4,7 +4,7 @@ {% else %} {% if field.label %}{{ field.label_tag() }}{% endif %} {% endif %} -{% if field.help_text %}
{{ field.help_text|safe }}
++ {{ field.help_text|safe }} +
{% endif %}