[BUG] Content component throws ReferenceError: field is not defined when HTML contains words matching i18n keys
@Victoriya25 is already working on this.
Since May 6, 2026.
Assessment
This issue has not been assessed yet.
Description
Environment
- Formio.js version: 4.21.0 (introduced in PR #4564 / commit 761fabb)
- Working version: 4.14.0
Steps to Reproduce
- Create a Content component with HTML pasted from a rich text editor (Google Docs, Microsoft Word, etc.)
- The pasted HTML wraps individual words in separate
<span>tags with inline styles (this is standard behavior for rich text editors) - Ensure the HTML body text contains common English words like "required", "unique", "pattern", "select", "min", or "max"
- Render the form
Example JSON:
{
"components": [
{
"type": "content",
"key": "content",
"html": "<p><span style=\"color:#3b3b00;\">should this be </span><span style=\"color:#3b3b00;\">required</span><span style=\"color:#000000;\">. </span></p>"
}
]
}
Observed Behavior
Console error:
Evaluator.js: Error interpolating template ReferenceError: field is not defined
The Content component fails to render.
Expected Behavior
The Content component should render the HTML as-is without errors.
Root Cause Analysis
PR #4564 (FIO-3939) changed Element.js:572 from:
if (typeof string !== 'function' && this.component.content
&& !FormioUtils.Evaluator.templateSettings.interpolate.test(string)) {
to:
if (typeof string !== 'function' && (this.component.content || this.component.html)
&& !FormioUtils.Evaluator.templateSettings.interpolate.test(string)) {
This was done to enable i18n translation for Content components (which use component.html, not component.content). However, it introduced a regression:
- The Content component's body HTML now passes through
translateHTMLTemplate(). translateHTMLTemplatewalks the DOM tree and callstranslateDeepTag→translateElemValueon each element.- Since
SPANis not in theinTextTagslist, the function recurses into each<span>individually. - When a
<span>contains only the text"required",this.t("required")is called. - FormIO's default i18n maps
"required"→"{{field}} is required". - The translated HTML now contains
{{field}}, which lodash_.template()tries to evaluate as JavaScript. fieldis not in the evaluation context ({utils, util, user, _, moment, ...}), so it throwsReferenceError: field is not defined.
This affects any word in the HTML that is isolated in its own element and exactly matches a FormIO i18n key. The most common collisions with natural English text are: required, unique, pattern, select, min, max, complete, error, cancel, submit, next, previous.
Rich text editors (Google Docs, Word) routinely wrap every few words in separate <span> tags with per-word styling, making this collision very likely for any form with legal/consent text.
Suggested Fix
The fix in translateHTMLTemplate/translateElemValue should either:
- Skip translations whose output introduces
{{ }}template expressions (to prevent lodash interpolation failures), or - Check if the translated value is a known validation message template before applying it, or
- Add
SPANto theinTextTagslist so spans are not translated individually
Simply reverting to this.component.content (removing || this.component.html) works but disables Content component i18n entirely.
Related Issues
- #3531 — Same category: i18n translations bleeding into content they shouldn't
- #5874 — Related:
{{field}}not being resolved in validation messages - #4608 — Related: HTML component interpolation issues
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 1.1k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from formio/formio.js
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
WizardBuilder: sidebar categories stop opening/closing after "+ Page" (addPage() rebuilds twice)Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
SelectBoxes.checkComponentValidity returns false without populating the caller's errors array, so required + minSelectedCount is never enforcedMay be free again @aliassar claimed this 16 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 4/5 3-5 days Newbie friendliness 54/100
All issues in formio/formio.js
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
anothaDev/luci-theme-vantage#143 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kingcharleslzy-ai/dsh-purge#282 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
a-corriger bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
christian-raj/S-Aloha#340 ·
-
area:image documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day