Title with error prefix
If you have a page containing a form, you should add the “Error: ” prefix to the page title if there is a validation error on the page.
This means that screen readers will read it out as soon as possible.
To do this, you can use the title_with_error_prefix helper.
If you are using a Rails form, you can set the error attribute by calling errors.any? on the form object:
= title_with_error_prefix("Personal details", error: @personal_details_form.errors.any?)
Title with an error present
Input
= title_with_error_prefix("Personal details", error: true)<%= title_with_error_prefix("Personal details", error: true) %>Title with an error present
Input
= title_with_error_prefix("Personal details", error: false)<%= title_with_error_prefix("Personal details", error: false) %>Title with a custom error prefix
Input
= title_with_error_prefix("Manylion personol", error: true, error_prefix: "Gwall: ")<%= title_with_error_prefix("Manylion personol", error: true, error_prefix: "Gwall: ") %>