Skip to content

Customisable error messages - #299

Merged
rossjones merged 15 commits into
mainfrom
815-customisable-error-messages
Sep 1, 2025
Merged

rossjones merged 15 commits into
mainfrom
815-customisable-error-messages

Conversation

@rossjones

@rossjones rossjones commented Aug 26, 2025 •

Copy link
Copy Markdown
Contributor

Error messages are currently generated by the backend validation functions, but are not able to be customised by our users.

This PR now returns error objects back to the client (prototype kit templates) so that they can choose what the error messages should contain if the language used by default is not suitable. These errors look like:

{ 
    variant: '' // The error generated,
    field: '' // The field that generated the error 
    type: '' // The expected type of the field 
    value: '' // The value found in the field where the error occurred
}

These properties for each error can be used in the templates, but the value field is not useful here as the errors are grouped by 'variant' and 'field' so that they appear together.

Currently it requires users to update both the error messages and the warning messages until we have more clarity on which 'errors' are in each category. It is possible to use the error 'variant' (type of error), the 'type' code (the expected type of that field) and the 'field' name in error messages, but the 'value' field is the value where the error was found, and this is not useful when errors are grouped together.

In future, we may with to move the error message customisation into the dudk itself so that it can be used by non-prototype kit users, and to re-instate backend support for customisable error messages, you can revert the commits 966afd6 and ee6f49d

Rather than generate the error message in the backend, we know generate
an error structure instead which can be used to generate error messages.
This functionality should live in the core dudk code, but be separate
from the general backend functionality as it is very front-end specific
and will be configured from a client.
These messages will be provided as a JSON object, containing the error
variants as keys and the messages to be interpolated as values.
@rossjones rossjones changed the title WIP: Customisable error messages Customisable error messages Aug 29, 2025
@rossjones
rossjones marked this pull request as ready for review August 29, 2025 13:57
@rossjones
rossjones requested review from alaric-rd and simonwo August 29, 2025 13:57
Comment thread prototypes/basic/app/views/review.html Outdated
Comment thread prototypes/basic/app/views/review.html Outdated
Comment thread prototypes/basic/app/views/review.html Outdated
Comment thread prototypes/basic/app/views/review.html Outdated
<h2 class="govuk-heading-m validation-error-message">{{warning.message}}</h2>
<p class="govuk-body">This warning occurs {{warning.meta.count | count_string}} in your data. The first time at row {{ warning.meta.first}}:</p>
<h2 class="govuk-heading-m validation-error-message">
{% switch warning.variant %}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to DRY this into a macro? Just one that is inline on this template? Whilst I don't think most people would naturally write macros, I guess they might recognise that changing the content in one will have the desired effect? Idk.

@rossjones rossjones Aug 29, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll be easier/better once we're not duplicating errors in warnings etc but will need to figure out which is which. I'll do that in this PR as I've found another error I'd missed anyway.

@rossjones
rossjones merged commit d801ac0 into main Sep 1, 2025
8 of 9 checks passed
@rossjones
rossjones deleted the 815-customisable-error-messages branch September 1, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants