question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it easy to generate the error summary with correct href values

See original GitHub issue

When you submit a form containing groups of fields such as radio buttons, populating the error summary so that focus is moved when the error link is clicked is problematic.

Say you have this:

<a href="#name-of-field">Enter blah</a>

And you have this:

<input type="radio" name="name-of-field" id="name-of-field-1" value="1">
<input type="radio" name="name-of-field" id="name-of-field-2" value="2">

When you click the link focus won’t move to the first <input> in the group. For that to work, we’d have to suffix the href with -1 to match the input’s id attribute value.

This means the server has to be told that a request that contains name-of-field is in fact a group of radios and therefore when the error summary is rendered for this particular error message, be sure to suffix it with -1.

This is a pain, and an unnecessary burden on the developer. What I’ve always done, is make sure the first input’s id in the group matches the name of the group. Like this:

<input type="radio" name="name-of-field" id="name-of-field" value="1">
<input type="radio" name="name-of-field" id="name-of-field-2" value="2">

This works nicely on the server side and on the client side (should a service implement client-side form validation).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
NickColleycommented, Jun 6, 2019

@adamsilver thanks for raising, this’ll be resolved in v3.0.0 👍 😄

1reaction
36degreescommented, Feb 1, 2019

Hey @adamsilver,

We did a lot of research into where the error summary should link to and found that for assistive technologies the best option was to link to the form input.

As you state, this means that the browser would scroll to the form control, leaving the legend or label outside of the viewport. To resolve this, we added JavaScript to the error summary component in #1056 which manually manages the focus and scroll behaviour to get the ‘best of both worlds’.

In https://github.com/alphagov/govuk-design-system/pull/634 we also added examples to the Design System to make it clearer where to link to – you can see this behaviour working on the examples on that page.

Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Disclosure Summary element - HTML - MDN Web Docs
The HTML element specifies a summary, caption, or legend for a element's disclosure box. Clicking the element toggles the state of the ...
Read more >
asp.net mvc 3 - Link in validation summary message
Finally I chose another way to do it: create a div containing the link etc. outside of validation summary, and add the div...
Read more >
HTML a href Attribute - W3Schools
Definition and Usage. The href attribute specifies the URL of the page the link goes to. If the href attribute is not present,...
Read more >
Error Explanations for The W3C Markup Validation Service
W3C's easy-to-use markup validation service, based on SGML and XML parsers.
Read more >
How to add error bars in Excel: standard and custom - Ablebits
If all done correctly, you will get individual error bars, proportional to the standard deviation values that you've calculated: Individual ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found