Opened 3 weeks ago

Closed 3 weeks ago

#36772 closed Bug (invalid)

`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.ModelForm for 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:

Attachments (1)

aria.7z (3.4 KB ) - added by cessor 3 weeks ago.

Download all attachments as: .zip

Change History (2)

by cessor, 3 weeks ago

Attachment: aria.7z added

comment:1 by Jacob Walls, 3 weeks ago

Resolution: invalid
Status: newclosed

Thanks for the test project. I noticed your test manually renders input fields instead of directly rendering the form. When a <fieldset> is in play, it's expected that the aria attribute will be on the <fieldset>, not the <input>, which is what's happening:

In [1]: from django.forms import *

In [2]: class UploadForm(ModelForm):
   ...:     class Meta:
   ...:         model = Upload
   ...:         fields = ["file"]
   ...: 

In [3]: from pprint import pprint

In [4]: pprint(UploadForm().as_div())
('<div>\n'
 '    <fieldset aria-describedby="id_file_helptext">\n'
 '  <legend>CSV-File:</legend>\n'
 '\n'
 '<div class="helptext" id="id_file_helptext">File containing comma separated '
 'values.</div>\n'
 '\n'
 '<input type="file" name="file" required id="id_file"></fieldset>\n'
 '    \n'
 '      \n'
 '    \n'
 '</div>')
Note: See TracTickets for help on using tickets.
Back to Top