When a form is submitted and there is a problem, communicating that problem
in a clear and concise manner is imperative. The form builder provides two
ways to do this.
Error messages are displayed immediately above the offending field.
They should tell the user how to fix the problem.
Additionally a summary of all the problems with the submission should be
displayed at the top of the page. Every error in the summary is a hyperlink
that when followed focusses on the problematic field.
This behaviour is provided by the form builder without any need for
extra configuration.
Some errors don’t apply to a specific field but the object as a whole.
The GOV.UK Design System guidelines suggest that in this case, the error
summary link should take the user to the first field. As the form builder
doesn’t know the order in which fields will be rendered, it must be specified.
Although the GDS design system recommends
that you use the same summary error message as that on the field there
may be situations in which the summary level wording can be used to
provide more or less context. Forms containing repeatable nested fields,
for example, could use the summary message to clearly point to an
attribute error instance.
In such cases a custom error presenter that responds to
#formatted_error_messages can be supplied. When a presenter
object is provided it will be used directly, when a class is provided it
will be instantiated with the associated object’s
#errors.messages.