Skip to content

FIO-10052: fix old conditional formats for select boxes #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/process/__tests__/fixtures/conditionalWithSelectBoxes.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 2 additions & 0 deletions src/process/__tests__/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -19,6 +20,7 @@ export {
skipValidForConditionallyHiddenComp,
skipValidWithHiddenParentComp,
forDataGridRequired,
conditionalWithSelectBoxes,
data1a,
form1,
subs,
Expand Down
25 changes: 25 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
addressComponentWithOtherCondComponents2,
clearOnHideWithCustomCondition,
clearOnHideWithHiddenParent,
conditionalWithSelectBoxes,
forDataGridRequired,
skipValidForConditionallyHiddenComp,
skipValidForLogicallyHiddenComp,
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formUtil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading