Opened 4 years ago
Closed 17 months ago
#32820 closed Bug (fixed)
Fields’ errors should be programmatically associated with fields.
Reported by: | Thibaud Colas | Owned by: | David Smith |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | accessibility, ui, forms |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
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 (15)
by , 4 years ago
Attachment: | email-required-aria-invalid.png added |
---|
comment:1 by , 4 years ago
Description: | modified (diff) |
---|
comment:2 by , 4 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 4 years ago
Summary: | Django forms - fields’ errors should be programmatically associated with fields → Fields’ errors should be programmatically associated with fields. |
---|
comment:4 by , 4 years ago
Hey, can I work on this? I'm a beginner here, any kind of help would be greatly appreciated.
Thanks,
Kiran
comment:5 by , 3 years ago
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 by , 3 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:9 by , 3 years ago
If I am not wrong, we need to remove the errorlist and use aria_techniques instead?
comment:10 by , 3 years ago
Owner: | changed from | to
---|
I will give this a try since there is inactivity.
comment:11 by , 3 years ago
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 by , 2 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
comment:13 by , 19 months ago
Owner: | changed from | to
---|---|
Version: | 3.2 → dev |
comment:15 by , 17 months ago
Owner: | changed from | to
---|---|
Patch needs improvement: | unset |
Screenshot of the VoiceOver text-to-speech output, announcing "Email required: required invalid data edit text"