Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility improvements for form validation #144

Open
Doniee opened this issue Mar 30, 2020 · 0 comments
Open

Accessibility improvements for form validation #144

Doniee opened this issue Mar 30, 2020 · 0 comments
Assignees
Labels
front-end front-end related issues

Comments

@Doniee
Copy link
Contributor

Doniee commented Mar 30, 2020

Notes from @fpapado:

  • novalidate on the form, as now

  • Have a hidden container for the error summary at the start of the form (inside the form)

<div class="error-summary hidden" aria-labelledby="error-summary-title" role="alert" tabindex="-1">
  <h2 id="error-summary-title">There is a problem</h2> 
  <div>
    <ul id="error-summary-list">
    </ul>
  </div>
</div>
  • On submit, go through the form fields and validate based on their attributes. Add each error description and that field's label (or fieldset) id to a list (e.g. [{description: "Fill in the cough symptoms", inputLabelId: "cough-label"}])

  • If there are errors, append a list item to the #error-summary-list
    <li><a href="#${inputLabelId}">{description}</a></li>

  • Also for each inputLabelId add the error after the label / legend (in p) with an id of ${inputLabelId}-error. Add aria-describedby to the fieldset or the label, referencing that error id.

  • Finally, display and focus #error-summary

This should give a good experience to users of different technologies and modalities.
It works without relying on the live regions on onBlur, which can be a bit disruptive.
It is all lifted from the GDS, which has the best resource I have seen on forms:
https://design-system.service.gov.uk/components/error-summary/
https://design-system.service.gov.uk/components/error-message/

@sjarva sjarva added the front-end front-end related issues label Apr 3, 2020
@sjarva sjarva self-assigned this Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
front-end front-end related issues
Projects
None yet
Development

No branches or pull requests

2 participants