Opened 4 hours ago
#36772 new Bug
`aria-describedby`-Attribute missing from file field HTML in Django 6.0
| Reported by: | cessor | Owned by: | |
|---|---|---|---|
| Component: | Forms | Version: | 6.0 |
| Severity: | Normal | Keywords: | forms, aria, fieldset, accessibility, admin |
| Cc: | cessor | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
In Django 6, input fields of type file do not render aria-describedby attributes. Those were introduced with Django 5.2. to facilitate use of screenreaders.
Steps to reproduce
- Create a model with a
file = models.FileField(...) - Render a
forms.ModelFormfor the model - The HTML for the input field should contain attribute
aria-describedby="id_file_helptext" - When Django 5.2 is installed the attribute is rendered
- When Django 6.0 is installed, the attribute is not rendered
Note that this issue affects FileFields but not CharFields. Both render HTML input elements. I did not test whether other fields are also affected.
I attached a zipfile with an example app. To reproduce the error, please create a .venv and install Django 5.2, then run manage.py tests; all will succeed. When installing Django 6, one test will fail. The module web.tests contains two tests, both check the input field HTML for aria-describedby, one is for a charfield, the other for a filefield.
Details
Consider Issue #35892 "Supported Widget.use_fieldset in admin forms.". In the scope of this ticked, a change was made to django.forms.widgets.ClearableFileInput, where as with commit 4187da2 the value ClearableFileInput.use_fieldset is set to True by default.
Because of this change, django.forms.boundfield.BoundField.build_widget_attrs does not add the "aria-describedby" attribute to the attrs dictionary which is then missing from the final response HTML.
Sources: