x-govuk/govuk-form-builder

HTML safe markup is ignored even when providing a custom presenter

Closed this issue · 1 comments

I've used a custom presenter to override the format of the error messages as we needed to mark HTML in error messages from I18n safe. This works for the error summary not for each individual field. I have attached an image and the PR for reference.

143570279-9758f714-fe64-4ff9-af5a-03d1ae6e2b57

PR - DFE-Digital/register-trainee-teachers#1771

The presenter only applies to the summary itself, the messages are built by ErrorMessage - a internal class we don't interact with at all from the outside.

I think #330 provides a sensible approach. There's a new setting that, when true, calls html_safe on all error messages before they're rendered. As the same errors are rendered in the error summary too, it'd make sense to extend the PR to apply there.

This brings the risk that if you include the input value in the error message (something that GOV.UK projects usually avoid) you' could potentially mark it as safe. For that reason it's disabled by default. This could be further enhanced to do it on a form-by-form basis, but that'd be a bigger change as we'd need a new argument on every helper.