Skip to content

Restore v4 error messages and add error message tests - #498

Open
alexluckett wants to merge 17 commits into
mainfrom
fix/v5-validation-messages
Open

alexluckett wants to merge 17 commits into
mainfrom
fix/v5-validation-messages

Conversation

@alexluckett

@alexluckett alexluckett commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This change fixes five validation messages that differ from v4 on v5 forms, and gives ComponentCollection.validate an English default. It also adds Welsh tests for the components and errors that the Welsh form test did not cover.

Key changes

  • The engine always validates with a translator. So these fixes change what users see on v5 forms. Each one gives the v4 text again:
    • A number field with a value that is not a number says "Age must be a number". Before, it said "Age must include a age" (NumberField used objectMissing).
    • Number, autocomplete and location fields put the label in lowercase: "Enter age". Before, they said "Enter Age" (they used objectRequired, which has no lowerFirst). The Welsh text changes in the same way: "Nodwch welsh Number field".
    • An optional autocomplete field with a value that is not in the list says "Select fruit". Before, it said "Enter fruit". The constructor sets its messages only for a required field, and the translated override now does the same.
    • The error summary keeps the page order. schema.keys() moved each field with a translated label to the end. replaceFieldSchema uses schema.fork(), which replaces each field in place.
    • A partly filled optional date or month says "must include a month". Before, it showed the key "components.dateField.month". The parent error now translates the label of a composite child.
  • validate uses English when it gets no translator, the same as the component methods. Before, a caller with no translator got keys in the errors, for example "Enter components.addressField.line1". Most of the diff in validate is indentation, because the if (translator) block is gone. Use "hide whitespace" to review it.
  • overrideParentTitle requires the translator, because validate always passes one. The branches for a missing translator are gone. The English text is the same, because parent.label and getTranslatedLabel use the same order of error description, short description and title.
  • SummaryViewModel formats the dates in its state errors with the locale of the translator. The message text stays English, because that validation uses the default messages. The summary page replaces these errors with its own page errors, so users see no change.
  • The global messages no longer have files.* and features.* keys. Joi names an error type after the schema type, so the file upload and map fields raise array.*, and these keys could never match an error. Each field sets its own array.* messages. test/form/file-upload-limits.test.js shows the same min, max and length errors before and after the removal, in English and Welsh.
  • The existing tests now expect the v4 text. Before, they expected keys, and that hid these errors. The comments that called the keys temporary are gone.
  • New Welsh tests render the page and check the error summary text and links:
    • test/form/components-translated.test.js covers the file upload field, page guidance and the payment field. The payment error comes from onSubmit at submission, so that test calls onSubmit directly. Html, InsetText and Details have no test, because the forms designer does not translate them.
    • test/form/errors-translated.test.js covers one error of each other template: text min length, pattern, number, email format, checkbox minimum, real date and the repeater minimum. The real date error is a separate POST, because it shows only when the other fields on the page are valid.
    • test/form/file-upload-limits.test.js covers the file upload min, max and length errors on a file upload page, with the upload service stubbed. One upload returns several files, as when a user selects several files, so that the page can go over its maximum.

alexluckett and others added 9 commits November 16, 2026 19:54
ComponentCollection.validate now uses English when it gets no translator,
the same as the component methods. Before, a caller with no translator got
i18n keys in the error text, for example
"Enter components.addressField.line1".

The tests for this showed four errors that users see on v5 forms. These
now give the v4 text again:

- A number field that is not a number says "must be a number". Before,
  it said "must include a <label>".
- Number, autocomplete and location fields put the label in lowercase in
  "Enter <label>", the same as other fields.
- The error summary keeps the page order. Before, each field with a
  translated label moved to the end.
- A partly filled optional date or month says "must include a month".
  Before, it showed the key.
The Welsh form test covers 19 question types. These tests add the file
upload field, page guidance and the payment field. Each one shows its
Welsh text, and its error in Welsh. Html, InsetText, Details and similar
content components are not tested, because the forms designer does not
translate them.
An optional autocomplete field with a value that is not in the list
showed "Enter <label>" when validated with a translator, and "Select
<label>" without one. The translated override now matches the
constructor, which sets its messages only for a required field.

Also correct the 'filees.length' message key to 'files.length'.
The Welsh form tests covered only the required errors. These tests post
invalid values to a Welsh form and check the error summary for the
min length, pattern, number, email format, checkbox minimum, real date
and repeater minimum errors.

SummaryViewModel now formats its state errors in the language of the
translator rather than in English, so that the errors property agrees
with the rest of the view model.
validate always passes a translator, so the checks for a missing
translator can never be true. The English path through parent.label is
the same text as getTranslatedLabel with the English translator, which
uses the same order of error description, short description and title.
The separate map and second loop are not necessary, because fork
replaces one field at a time.
The method name and its comment say why fork is used: the field keeps
its position, so that the errors stay in page order.
@alexluckett
alexluckett marked this pull request as ready for review November 17, 2026 19:21
The upload service is stubbed. A single upload returns several files, as
when a user selects several files, so that the page can go over its
maximum.
Joi names an error type after the schema type, so the file upload and
map fields raise array.min, array.max and array.length. No schema has
the type files or features, so these keys could never match an error.
Each field sets its own array messages, which the file upload limits
test shows are the same before and after this change.
…ngine-plugin into fix/v5-validation-messages
The repeat form is a V1 form, so the Welsh test uses its own small V2
repeater form.
The other errors-translated checks repeated the email, checkbox, date
and pattern checks in that test, so errors-translated is removed.
@sonarqubecloud

Copy link
Copy Markdown

@Scullyon
Scullyon self-requested a review November 19, 2026 14:54
@alexluckett
alexluckett added this pull request to stack #502 November 19, 2026 15:03

@Scullyon Scullyon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just the one thing to look at, otherwise looks fine to me.

// Format errors
this.errors = result.error?.details.map((item) => getError(item, EN_GB))
this.errors = result.error?.details.map((item) =>
getError(item, translator.language)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude thinks that dates now follow the session language, whereas the words are still in English.

'array.max': messageTemplate.arrayMax,
'array.length': messageTemplate.arrayLength,

'features.min': messageTemplate.featuresMin,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm sure these had a purpose, it's bugging me but there's no reference to them anymore so 🤷‍♂️ .

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants