Repository navigation
Fix conditionals when the condition component key is numeric - #314
Open
aviral14112001 wants to merge 1 commit into
Open
aviral14112001 wants to merge 1 commit into
aviral14112001 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
If a component's API key is numeric, e.g.
507, and another component has a simple conditional on it ("showtextField1when507is equal totrue"), the builder saves the condition as:componentis the number507, not the string"507". The builder's "When" select usesdataType: 'auto', andSelect.normalizeSingleValuerunsstring().number().boolean()forauto, so numeric strings become numbers. The legacyconditional.whenselect works the same way.checkSimpleConditional/checkLegacyConditionalpass that value togetComponent/getComponentValue. From there,componentMatchesexpects a string path:paths[type] === path, so"507" === 507never matches. The condition then evaluates againstnull, andtextField1stays conditionally hidden even when507istrue, so validation andclearOnHideact on the wrong state.selectboxescomponent, it callspath.match(...), which throwsTypeError: path.match is not a functionand 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 theconditionsprocessor 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 onmainwithTypeError: path.match is not a functionand pass with this change.TEST=1 mocha --loader=tsx: 621 passing, 0 failingtsc --noEmit: cleaneslint: no new warningsRelated
The renderer has its own copy of
checkSimpleConditionalin@formio/js, which throwsTypeError: conditionComponentPath.split is not a functionfor the same form. That fix is in the companion PR formio/formio.js#6349.🤖 Generated with Claude Code