Skip to content

[Element Editor] Render element validation errors as a list without the error. prefix#3910

Open
mw-keoz wants to merge 3 commits into
pimcore:2026.2from
mw-keoz:fix/element-validation-error-list-2026x
Open

[Element Editor] Render element validation errors as a list without the error. prefix#3910
mw-keoz wants to merge 3 commits into
pimcore:2026.2from
mw-keoz:fix/element-validation-error-list-2026x

Conversation

@mw-keoz

@mw-keoz mw-keoz commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

Render element-validation errors as a bulleted list of the server-provided violation messages, instead of one error.-prefixed line.

Why

When saving an element fails validation, the backend (studio-backend-bundle) returns HTTP 422 with errorKey = error_element_validation_failed and message holding the human-readable, server-combined violation text (one violation per line).

ApiErrorViewUI treats errorContent.errorKey as an i18n key and renders t(error.${errorKey}). Because the value is free text (not a translation key), i18next returns the raw string with a literal error. prefix, collapsed onto a single line. Users see e.g.:

error.The button text must not be empty. Link 1: A text must be provided.

This affects every element whose validator fails, not just custom classes.

Fix

Detect the ELEMENT_VALIDATION_FAILED case and render the message directly through the existing SanitizeHtml (DOMPurify keeps ul/li), bypassing t(): a single violation renders as a plain line, multiple as an unordered list. A small unit-tested helper (formatValidationErrorHtml) does the split/format.

  • api-error-view-ui.tsx — add the ELEMENT_VALIDATION_FAILED branch (falls through to the existing behavior for every other error).
  • utils/format-validation-error.ts (+ .test.ts) — new helper, POCL header included.

No change to any other error path.

Testing

  • npx jest format-validation-error — single line, multi-line → <ul>, blank-line/whitespace trimming, empty input → ''.
  • Manual: save an object with ≥2 failing mandatory/regex validators → the modal shows a clean bulleted list, no error. prefix; a single violation shows as one line.
  • Content is rendered via the existing SanitizeHtml/DOMPurify, so only ul/li and inline text survive (no new XSS surface).

Copilot AI review requested due to automatic review settings July 21, 2026 06:32
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI 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.

Pull request overview

Fixes element-validation messages by bypassing translation and formatting newline-separated violations as a list.

Changes:

  • Adds validation-error formatting.
  • Handles element-validation errors separately in ApiErrorViewUI.
  • Adds formatter unit tests.

Review assessment:

  • Root cause addressed at api-error-view-ui.tsx:30-35.
  • Shared ApiErrorViewUI call path is covered without API changes.
  • Formatter tests cover splitting, but not the translation-bypass integration.
  • format-validation-error.ts:23-27 interpolates unescaped text into HTML; changes required.
  • No documentation or changelog update is included.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
api-error-view-ui.tsx Renders element-validation messages directly.
format-validation-error.ts Formats violations as text or a list.
format-validation-error.test.ts Tests formatter behavior.

mw-keoz added 3 commits July 21, 2026 10:28
…he error. prefix

On a failed element save the backend returns errorKey=error_element_validation_failed
with 'message' holding the human-readable, server-combined violation text (one per
line). The error view treated errorKey as an i18n key and rendered
t(`error.${errorKey}`), so the free-text message showed with a literal 'error.'
prefix collapsed onto a single line. Detect this case and render the message
directly via SanitizeHtml (DOMPurify keeps ul/li): a single violation as a plain
line, multiple as an unordered list. Adds a unit-tested formatValidationErrorHtml
helper.
The violation message was interpolated into the HTML string unescaped. Because
SanitizeHtml (DOMPurify) keeps its default allowlist (headings, links, images,
list items, …), HTML-like text in a message would render as markup instead of
being shown literally, and an injected </li><li> could forge extra list items.
HTML-escape each violation (both the single-line and list paths) so the ul/li
wrapper is the only markup; add regression tests with HTML-like input.
…matter

Extract the <li> items into a variable so the <ul> template no longer nests a
template literal (SonarCloud typescript:S4624). No behavior change.
@mw-keoz
mw-keoz force-pushed the fix/element-validation-error-list-2026x branch from a7a176e to 967f0a9 Compare July 21, 2026 08:29
@mw-keoz
mw-keoz changed the base branch from 2026.x to 2026.2 July 21, 2026 08:29
@sonarqubecloud

Copy link
Copy Markdown

@ValeriaMaltseva
ValeriaMaltseva requested a review from vin0401 July 22, 2026 14:59
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.

2 participants