Opened 22 months ago
Last modified 3 months ago
#32820 assigned Bug
Fields’ errors should be programmatically associated with fields.
Reported by: | Thibaud Colas | Owned by: | Demetris Stavrou |
---|---|---|---|
Component: | Forms | Version: | 3.2 |
Severity: | Normal | Keywords: | accessibility, ui, forms |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Related: #32819. This could be worth fixing at the same time, although I would expect this issue shouldn’t require as breaking of a change to fix.
Django currently displays errors above fields in its forms rendering:
<ul class="errorlist"> <li>This field is required.</li> </ul> <p> <label for="id_duration_required">Duration required:</label> <input type="text" name="duration_required" required="" id="id_duration_required"> <span class="helptext">Help</span> </p>
One thing this is missing is a way to programmatically indicate the field is in error – currently this can only be inferred visually because the error messages are displayed above the field. This is fail of WCAG 2.1 level A 3.3.1: Error Identification. The most common way to do this programmatically is to use aria-invalid="true"
on the field, as demonstrated in the non-normative technique ARIA21:
<input type="text" name="duration_required" required="" id="id_duration_required" aria-invalid="true">
Here is the result in VoiceOver on Safari – announcing "invalid data" after the field label and required state:
Attachments (1)
Change History (11)
Changed 22 months ago by
Attachment: | email-required-aria-invalid.png added |
---|
comment:1 Changed 22 months ago by
Description: | modified (diff) |
---|
comment:2 Changed 22 months ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 Changed 22 months ago by
Summary: | Django forms - fields’ errors should be programmatically associated with fields → Fields’ errors should be programmatically associated with fields. |
---|
comment:4 Changed 22 months ago by
Hey, can I work on this? I'm a beginner here, any kind of help would be greatly appreciated.
Thanks,
Kiran
comment:5 Changed 21 months ago by
Kiran, assign yourself the ticket if you want to take it. If you need help, I would first read https://docs.djangoproject.com/en/3.2/internals/contributing/ and try to get the tests passing at least.
You would probably need to find where the HTML for these forms are generated. I think https://github.com/django/django/tree/main/django/forms/templates/django/forms/widgets might be a good place to start. Then find out the best way to tell if the field is invalid and the best place to add the attribute.
If you get stuck, you could try posting on the forum or the django-developers mailing list.
comment:8 Changed 19 months ago by
Owner: | set to Kapil Bansal |
---|---|
Status: | new → assigned |
comment:9 Changed 19 months ago by
If I am not wrong, we need to remove the errorlist and use aria_techniques instead?
comment:10 Changed 17 months ago by
Owner: | changed from Kapil Bansal to Demetris Stavrou |
---|
I will give this a try since there is inactivity.
comment:11 Changed 15 months ago by
Note based on recent research for PR #15036:
- I still think this is a _Bug_ (WCAG 2.1 conformance fail) as Django stands currently, however if/when ticket #32819 is tackled, we should mark this ticket as a _New feature_, as contrary to what I thought
aria-invalid="true"
isn’t required for conformance whenaria-describedby
already points to an error message. If the error message can’t be identified as such, then the bug to fix would be to make the error messages unambiguous, which is a different issue. - Even though I would expect fixing this to be a straightforward improvement for almost all Django implementers, it’ll change how forms are announced to screen reader users, so it would be valid to consider this as a breaking change.
comment:12 Changed 3 months ago by
Has patch: | set |
---|---|
Patch needs improvement: | set |
Screenshot of the VoiceOver text-to-speech output, announcing "Email required: required invalid data edit text"