Errors on the base object result in broken summary link
FriedSock opened this issue · 4 comments
If there is an error that can't be attributed to a specific field, the link for the error will be of the form #object-base-field-error
, for which there is no element with that id on the page. In this case I think the form should add this id to the first input field in the form, or to the form itself.
Hi, thanks for reporting this. Your suggestion fits in with that of the design system recommendation:
If you do not know which field contains an error, link to the first field.
Unfortunately, due to the way the underlying Rails form builder is written, it's really difficult to know which the first field rendered will be when we're rendering the #govuk_error_summary
.
Linking to the form itself might be more-straightforward; the gem could provide a helper method to return an appropriate id
.
I'll have a think on it. Suggestions on approach welcome.
@FriedSock - would you mind providing a bit of context around your particular use case? We had a discussion internally and found that in most instances a failing form submission should be tied to at least one of the inputs.
@peteryates Yes, thank you for looking in to this so quickly.
The case is: a user is required to submit an email address or a phone number, when they don't supply either there is a validation error on the base object, I don't think it would be correct to add errors to both of the fields since neither are strictly required by themselves.
@FriedSock - please let me know your thoughts on #209. I feel like this is the best approach.