Problem/Motivation
When the inline form error module is enabled, there is not an aria-errormessage attribute available in the form element. Therefore, the screen reader does not properly or accurately read out the form element's error message.
Currently, the form element has an aria-describedby attribute which the screen reader will read out as an error message. The aria-describedby points to text that describes the form element, but it is not an error message.
Steps to reproduce
- Clone drupal core and switch to this issue fork
- Add
$settings["extension_discovery_scan_tests"] = TRUE;toweb/sites/default/settings.php - Install the "Inline Form Errors"/
inline_form_errorsmodule and the "FormAPI Test"/form_testmodule (i.e.: fromcore/modules/system/tests/modules/form_test) - Go to
/form-test/form-test-machine-name-validation - Without changing any form values, click the Save button
- Expected behavior:
- I see the Error message "3 errors have been found" at the top, linking to each control.
- I see the error message "Name field is required." under the Name field. When I view the HTML, the HTML input tag for the Name field has an aria-errormessage attribute pointing to the error message, which has a unique HTML ID.
- I see the error message "A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores." under the Machine-readable name field. When I view the HTML, the HTML input tag for the Machine-readable name field has an aria-errormessage attribute pointing to the error message, which has a unique HTML ID.
- I see the error message "Select a snack field is required" under the Snack field. When I view the HTML, the HTML select tag for the Select a snack field has an aria-errormessage attribute pointing to the error message, which has a unique HTML ID.
- Actual behavior:
- I see the Error message "3 errors have been found" at the top, linking to each control.
- I see the error message "Name field is required." under the Name field. When I view the HTML, the HTML input tag for the Name field has no aria-errormessage attribute pointing to the error message. The error message itself has no ID attribute.
- I see the error message "A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores." under the Machine-readable name field. When I view the HTML, the HTML input tag for the Machine-readable name field has no aria-errormessage attribute pointing to the error message. The error message itself has no ID attribute.
- I see the error message "Select a snack field is required" under the Snack field. When I view the HTML, the HTML select tag for the Snack field has no aria-errormessage attribute pointing to the error message. The error message itself has no ID attribute.
- Expected behavior:
Proposed resolution
- Wrap the error message in a div with an ID attribute:
<div class="form-item__error-message"><div id="title_error">Title field is required.</div></div> - Add the aria-errormessage attribute to the form element which references the ID attribute of the corresponding error message.
<input aria-errormessage="title_error"/>
We're intentionally scoping this work to the inline form errors module otherwise this would be a change to the Form API and a bunch of Twig templates in Drupal Core's modules and themes, in addtion affecting contributed themes.
Remaining tasks
Add a merge request- merge request !15815- Review
- Address maintainer feedback
- Backport to Drupal 11?
- Backport to Drupal 10?
User interface changes
When the inline form error module is enabled, the form control will get an aria-errormessage attribute when the form element has an error. The aria attribute will point to the error message.
Introduced terminology
To be determined (probably none)
API changes
None
Data model changes
None
Release notes snippet
To be determined
Issue fork drupal-3590902
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
photojennylee commentedUpdated the steps to reproduce
Comment #4
photojennylee commentedI have created merge request !15815.
Let's see if tests pass.
Comment #5
photojennylee commentedTests passed. I am ready for other people to take a look at the merge request.
Comment #6
smustgrave commentedLeft a comment on the MR but also something that will need test coverage please.
Comment #7
kentr commentedThink this is a duplicate of #3083103: Programmatically associate error messages with inputs, which would handle this for all form errors, not just when Inline Form Errors is enabled.
Also, it's under discussion by the accessibility team whether we actually want to use
aria-errormessageat all due to issues in different user agents / screen readers.