Skip to content

Fix conditionals when the condition component key is numeric - #314

Open
aviral14112001 wants to merge 1 commit into
formio:mainfrom
aviral14112001:fix/numeric-condition-component-key
Open

aviral14112001 wants to merge 1 commit into
formio:mainfrom
aviral14112001:fix/numeric-condition-component-key

Conversation

@aviral14112001

@aviral14112001 aviral14112001 commented Nov 2, 2026 •

Copy link
Copy Markdown

Problem

If a component's API key is numeric, e.g. 507, and another component has a simple conditional on it ("show textField1 when 507 is equal to true"), the builder saves the condition as:

"conditional": {
  "show": true,
  "conjunction": "all",
  "conditions": [{ "component": 507, "operator": "isEqual", "value": true }]
}

component is the number 507, not the string "507". The builder's "When" select uses dataType: 'auto', and Select.normalizeSingleValue runs string().number().boolean() for auto, so numeric strings become numbers. The legacy conditional.when select works the same way.

checkSimpleConditional / checkLegacyConditional pass that value to getComponent / getComponentValue. From there, componentMatches expects a string path:

  • It compares paths with paths[type] === path, so "507" === 507 never matches. The condition then evaluates against null, and textField1 stays conditionally hidden even when 507 is true, so validation and clearOnHide act on the wrong state.
  • When the form contains any selectboxes component, it calls path.match(...), which throws TypeError: path.match is not a function and breaks processing.

Fix

In src/utils/conditions.ts, normalize the condition's component path to a string before resolving it, for both simple (conditions[].component) and legacy (when) conditionals. Both the conditions processor and logic triggers use these functions, so the fix covers both.

Tests

There are two new cases in src/process/conditions/__tests__/conditions.test.ts: one for a simple conditional and one for a legacy conditional, each with a numeric key and a selectboxes component in the form. Both fail on main with TypeError: path.match is not a function and pass with this change.

  • TEST=1 mocha --loader=tsx: 621 passing, 0 failing
  • tsc --noEmit: clean
  • eslint: no new warnings

Related

The renderer has its own copy of checkSimpleConditional in @formio/js, which throws TypeError: conditionComponentPath.split is not a function for the same form. That fix is in the companion PR formio/formio.js#6349.

🤖 Generated with Claude Code

A component key such as "507" is saved as the number 507 in
conditional.conditions[].component (and conditional.when) because the
builder's select uses dataType "auto", which converts numeric strings to
numbers. Path matching in getComponentFromPath compares paths with === and
calls path.match(), so the condition either silently evaluated to false or
threw "TypeError: path.match is not a function" when the form contained a
selectboxes component. Normalize the condition component path to a string
before resolving it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant