diff --git a/src/process/__tests__/fixtures/conditionalWithSelectBoxes.json b/src/process/__tests__/fixtures/conditionalWithSelectBoxes.json new file mode 100644 index 00000000..79a754d5 --- /dev/null +++ b/src/process/__tests__/fixtures/conditionalWithSelectBoxes.json @@ -0,0 +1,79 @@ +{ + "form": { + "title": "9.2.4 select boxes", + "name": "924SelectBoxes", + "path": "924selectboxes", + "type": "form", + "display": "form", + "components": [ + { + "label": "Select Boxes", + "optionsLabelPosition": "right", + "tableView": false, + "values": [ + { + "label": "dog", + "value": "dog", + "shortcut": "" + }, + { + "label": "cat", + "value": "cat", + "shortcut": "" + }, + { + "label": "bird", + "value": "bird", + "shortcut": "" + } + ], + "validateWhenHidden": false, + "key": "selectBoxes", + "type": "selectboxes", + "input": true, + "inputType": "checkbox" + }, + { + "label": "Text Field", + "applyMaskOn": "change", + "tableView": true, + "validateWhenHidden": false, + "key": "textField", + "conditional": { + "show": true, + "conjunction": "all", + "conditions": [ + { + "component": "selectBoxes.dog", + "operator": "isEqual", + "value": "true" + } + ] + }, + "type": "textfield", + "input": true + }, + { + "type": "button", + "label": "Submit", + "key": "submit", + "disableOnInvalid": true, + "input": true, + "tableView": false + } + ], + "created": "2025-05-12T11:49:34.499Z", + "modified": "2025-05-12T11:49:34.511Z" + }, + "submission": { + "data": { + "selectBoxes": { + "dog": true, + "cat": false, + "bird": false + }, + "textField": "12", + "submit": true + } + } +} \ No newline at end of file diff --git a/src/process/__tests__/fixtures/index.ts b/src/process/__tests__/fixtures/index.ts index 2a576ef6..62ecb474 100644 --- a/src/process/__tests__/fixtures/index.ts +++ b/src/process/__tests__/fixtures/index.ts @@ -5,6 +5,7 @@ import skipValidForLogicallyHiddenComp from './skipValidForLogicallyHiddenComp.j import skipValidWithHiddenParentComp from './skipValidWithHiddenParentComp.json'; import addressComponentWithOtherCondComponents from './addressComponentWithOtherCondComponents.json'; import addressComponentWithOtherCondComponents2 from './addressComponentWithOtherCondComponents2.json'; +import conditionalWithSelectBoxes from './conditionalWithSelectBoxes.json'; import forDataGridRequired from './forDataGridRequired.json'; import data1a from './data1a.json'; import form1 from './form1.json'; @@ -19,6 +20,7 @@ export { skipValidForConditionallyHiddenComp, skipValidWithHiddenParentComp, forDataGridRequired, + conditionalWithSelectBoxes, data1a, form1, subs, diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 204c8b9b..2cd50bb6 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -9,6 +9,7 @@ import { addressComponentWithOtherCondComponents2, clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, + conditionalWithSelectBoxes, forDataGridRequired, skipValidForConditionallyHiddenComp, skipValidForLogicallyHiddenComp, @@ -3834,6 +3835,30 @@ describe('Process Tests', function () { assert.equal(context.scope.errors.length, 0); }); + it('Should set data for fields with old conditional formats for Select Boxes', async function () { + const errors: any = []; + const { form, submission } = conditionalWithSelectBoxes; + const context = { + form, + submission, + data: submission.data, + components: form.components, + processors: ProcessTargets.submission, + scope: { errors }, + config: { + server: true, + }, + }; + processSync(context); + submission.data = context.data; + context.processors = ProcessTargets.evaluator; + processSync(context); + (context.scope as any).conditionals.forEach((v: any) => + assert.equal(v.conditionallyHidden, false), + ); + assert.deepEqual(context.data, submission.data); + }); + it('Should not unset values for conditionally visible fields with different formats of condtion based on selectboxes value', async function () { const form = { _id: '66ffa92ac25689df8702f283', diff --git a/src/utils/formUtil/index.ts b/src/utils/formUtil/index.ts index ccaef7f5..40f313b9 100644 --- a/src/utils/formUtil/index.ts +++ b/src/utils/formUtil/index.ts @@ -385,7 +385,7 @@ export function componentMatches( ) { let dataProperty = ''; if (component.type === 'selectboxes') { - const valuePath = new RegExp(`(\\.${escapeRegExp(component.key)})(\\.[^\\.]+)$`); + const valuePath = new RegExp(`(\\.?${escapeRegExp(component.key)})(\\.[^\\.]+)$`); const pathMatches = path.match(valuePath); if (pathMatches?.length === 3) { dataProperty = pathMatches[2];