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

Add anchor links between error summary items and inputs #10

Merged
merged 19 commits into from
Jul 20, 2019

Conversation

peteryates
Copy link
Member

The GOV.UK Design System suggests that the anchor links in error summaries should link to actual form inputs, they previously linked to the error message that is associated with the field. This work adds the linking functionality to this form builder.

Errors on fields that have a single element are directly linked. These include

  • Text inputs
  • Telephone inputs
  • Email inputs
  • URL inputs
  • Number inputs
  • File inputs
  • Select boxes

Errors on date fields always link to the day. Ruby has no concept of part of a date being invalid, so we link to the first input in the group.

Errors on fields with multiple elements, namely radio buttons and check boxes, link to the first radio or checkbox. For the collection methods this happens automatically. For #govuk_radio_buttons_fieldset an extra parameter is required on the first radio button, link_errors should be set to true.

Fixes #9

Having no control of the ids is problematic when making the error
summary list link _directly_ to the element because, in the case of
multi-input fields (like radios and checkboxes) we don't know what's
available or what's first

This is the first step towards making all error summary links behave as
specified in the GOV.UK Design System

https://design-system.service.gov.uk/components/error-summary/#linking-from-the-error-summary-to-each-answer

Refs #9
Ruby can't validate individual elements of a date so when a date is
invalid make the error summary link focus the day field
We're passing in the block arg but not using it which is making the
linter complain. However, builder requires it to be explicit so it's
used by #initialize instead of #html
@peteryates peteryates added enhancement New feature or request accessibility Making it easier for people with disabilities labels Jul 20, 2019
@peteryates peteryates merged commit 59dc130 into master Jul 20, 2019
@peteryates peteryates deleted the error-summary-links branch July 20, 2019 19:21
peteryates added a commit that referenced this pull request Jan 9, 2020
The GOV.UK Design System suggests that the anchor links in error summaries should link
to actual form inputs[0], they previously linked to the error message that is associated with
the field. This work adds the linking functionality to this form builder.

* Errors on fields that have a single element are directly linked. These include: text inputs,
  telephone inputs, email inputs, url inputs, number inputs, file inputs and select boxes

* Errors on date fields always link to the day. Ruby has no concept of part of a date being
  invalid, so we link to the first input in the group.

* Errors on fields with multiple elements, namely radio buttons and check boxes, link to the
  first radio or checkbox. For the collection methods this happens automatically. For
  #govuk_radio_buttons_fieldset an extra parameter is required on the first radio button,
  link_errors should be set to true.

Fixes #9

[0] https://design-system.service.gov.uk/components/error-summary#linking-from-the-error-summary-to-each-answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility Making it easier for people with disabilities enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error summary links
1 participant