Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #32819 -- Used auto_id instead of id_for_label as unique identifier for the field. #17480

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

smithdc1
Copy link
Member

id_for_label is blank for widgets with multiple inputs such as radios and multiple checkboxes. Therefore , help_text for fields using these widgets can not currently be associated using aria-describedby. id_for_label is being used as a guard to avoid incorrectly adding aria-describedby to those widgets.

This change uses auto_id as the unique identified for the fields help_text. A guard is added to avoid incorrectly adding aria-describedby to inputs by checking the widget's use_fieldset attribute. Fields rendered in a <fieldset> should have aria-describedby added to the <fieldset> and not every <input>.

@@ -395,7 +395,7 @@ be ignored in favor of the value from the form's initial data.
.. versionadded:: 5.0

The ``template_name`` argument allows a custom template to be used when the
field is rendered with :meth:`~django.forms.BoundField.as_field_group`. By
field is rendered with :meth:`~django.forms.BoundField.as_field_group`. By
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to commit a change to this file without adding this whitespace change.

):
attrs["aria-describedby"] = f"{self.id_for_label}_helptext"
attrs["aria-describedby"] = f"{self.auto_id}_helptext"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in 966ecdd (Django 5.0). I'd recommend backporting this change to the Django 5.0 to avoid changes in Django 5.1 in recently added functionality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable.

I was wondering if you may have triaged the other pr as a release blocker. I think it's not as we we've only recently agreed on a way forward for fields with related <inputs>.

Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smithdc1 Thanks 👍 I pushed small docs changes, assuming this change would be backported.

…ier for the field.

`id_for_label` is blank for widgets with multiple inputs such as radios
and multiple checkboxes. Therefore , `help_text` for fields using these
widgets cannot currently be associated using `aria-describedby`.
`id_for_label` is being used as a guard to avoid incorrectly adding
`aria-describedby` to those widgets.

This change uses `auto_id` as the unique identified for the fields
`help_text`. A guard is added to avoid incorrectly adding
`aria-describedby` to inputs by checking the widget's `use_fieldset`
attribute. Fields rendered in a `<fieldset>` should have
`aria-describedby` added to the `<fieldset>` and not every `<input>`.
@felixxm felixxm merged commit 292f1ea into django:main Nov 16, 2023
36 checks passed
@smithdc1 smithdc1 deleted the aria-describedby-autoid branch November 16, 2023 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants