Skip to content
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
2 changes: 2 additions & 0 deletions src/process/__tests__/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import forDataGridRequired from './forDataGridRequired.json';
import data1a from './data1a.json';
import form1 from './form1.json';
import subs from './subs.json';
import requiredFieldInsideEditGrid from './requiredFieldInsideConditionalEditGrid.json';
import formWithDefaultValues from './componentsWithDefaultValues.json';

export {
Expand All @@ -25,5 +26,6 @@ export {
data1a,
form1,
subs,
requiredFieldInsideEditGrid,
formWithDefaultValues,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[{
"key": "selectGrids",
"type": "radio",
"input": true,
"label": "Select grids",
"inline": false,
"values": [{
"label": "Show grid 1",
"value": "showGrid1",
"shortcut": ""
},
{
"label": "Show grid 2",
"value": "showGrid2",
"shortcut": ""
}
],
"tableView": false,
"validateWhenHidden": false,
"optionsLabelPosition": "right"
},
{
"key": "grid2",
"type": "editgrid",
"input": true,
"label": "Grid 2",
"rowDrafts": false,
"tableView": false,
"components": [{
"label": "Checkbox",
"tableView": false,
"validateWhenHidden": false,
"key": "checkbox",
"type": "checkbox",
"input": true
},
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"validate": {
"required": true
},
"validateWhenHidden": false,
"key": "textField",
"conditional": {
"show": true,
"conjunction": "all",
"conditions": [{
"component": "grid2.checkbox",
"operator": "isEqual",
"value": true
}]
},
"type": "textfield",
"input": true
},
{
"key": "requiredField",
"type": "textfield",
"input": true,
"label": "Required field",
"validate": {
"required": true
},
"tableView": true,
"applyMaskOn": "change",
"validateWhenHidden": false
}
],
"conditional": {
"show": true,
"conditions": [{
"value": "showGrid2",
"operator": "isEqual",
"component": "selectGrids"
}],
"conjunction": "all"
},
"displayAsTable": false,
"validateWhenHidden": false
},
{
"key": "submit",
"type": "button",
"input": true,
"label": "Submit",
"tableView": false,
"disableOnInvalid": true
}
]
23 changes: 23 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
skipValidForConditionallyHiddenComp,
skipValidForLogicallyHiddenComp,
skipValidWithHiddenParentComp,
requiredFieldInsideEditGrid,
formWithDefaultValues,
} from './fixtures';
import _ from 'lodash';
Expand Down Expand Up @@ -897,7 +898,7 @@
form: '65ea368b705068f84a93c87a',
};

const errors: any = [];

Check warning on line 901 in src/process/__tests__/process.test.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
const context = {
_,
form,
Expand Down Expand Up @@ -1039,7 +1040,7 @@
},
},
};
const errors: any = [];

Check warning on line 1043 in src/process/__tests__/process.test.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
const context = {
form,
submission,
Expand Down Expand Up @@ -1380,7 +1381,7 @@
form: '65e8786fc5dacf667eef12fc',
};

const errors: any = [];

Check warning on line 1384 in src/process/__tests__/process.test.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
const context = {
form,
submission,
Expand Down Expand Up @@ -1576,7 +1577,7 @@
form: '65e8786fc5dacf667eef12fc',
};

const errors: any = [];

Check warning on line 1580 in src/process/__tests__/process.test.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
const context = {
form,
submission,
Expand Down Expand Up @@ -1856,7 +1857,7 @@
};

const submission = { data: { selector: 'two' } };
const errors: any = [];

Check warning on line 1860 in src/process/__tests__/process.test.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
const context = {
form,
submission,
Expand Down Expand Up @@ -1947,7 +1948,7 @@
},
};

const errors: any = [];

Check warning on line 1951 in src/process/__tests__/process.test.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
const context = {
form,
submission,
Expand Down Expand Up @@ -2037,7 +2038,7 @@
},
};

const errors: any = [];

Check warning on line 2041 in src/process/__tests__/process.test.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
const context = {
form,
submission,
Expand Down Expand Up @@ -6622,5 +6623,27 @@
processSync(context);
assert.equal(!!context.data.textField, false);
});

it('Should not show validation errors for required component inside conditionally hidden editGrid', async function () {
const components = requiredFieldInsideEditGrid;
const submission = {
data: {
selectGrids: '',
submit: true,
},
};
const context = {
submission,
data: submission.data,
components,
processors: ProcessTargets.submission,
scope: {} as { errors: Record<string, unknown>[] },
};
processSync(context);
submission.data = context.data;
context.processors = ProcessTargets.evaluator;
processSync(context);
expect(context.scope.errors.length).to.equal(0);
});
});
});
41 changes: 34 additions & 7 deletions src/utils/formUtil/eachComponentData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const eachComponentData = (
local: boolean = false,
parent?: Component,
parentPaths?: ComponentPaths,
noScopeReset?: boolean,
) => {
if (!components) {
return;
Expand All @@ -56,7 +57,9 @@ export const eachComponentData = (
compPaths,
) === true
) {
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
}
if (isComponentNestedDataType(component)) {
Expand All @@ -81,6 +84,7 @@ export const eachComponentData = (
local,
component,
compPaths,
noScopeReset,
);
}
} else if (includeAll || isUndefined(value)) {
Expand All @@ -92,13 +96,18 @@ export const eachComponentData = (
local,
component,
compPaths,
noScopeReset,
);
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
} else {
if (!includeAll && !shouldProcessComponent(component, row, value)) {
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
}
eachComponentData(
Expand All @@ -109,15 +118,27 @@ export const eachComponentData = (
local,
component,
compPaths,
noScopeReset,
);
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
} else if (!component.type || getModelType(component) === 'none') {
const info = componentInfo(component);
if (info.hasColumns) {
(component as HasColumns).columns.forEach((column: any) =>
eachComponentData(column.components, data, fn, includeAll, local, component, compPaths),
eachComponentData(
column.components,
data,
fn,
includeAll,
local,
component,
compPaths,
noScopeReset,
),
);
} else if (info.hasRows) {
(component as HasRows).rows.forEach((row: any) => {
Expand All @@ -131,6 +152,7 @@ export const eachComponentData = (
local,
component,
compPaths,
noScopeReset,
),
);
}
Expand All @@ -144,12 +166,17 @@ export const eachComponentData = (
local,
component,
compPaths,
noScopeReset,
);
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return false;
},
true,
Expand Down
31 changes: 25 additions & 6 deletions src/utils/formUtil/eachComponentDataAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const eachComponentDataAsync = async (
local: boolean = false,
parent?: Component,
parentPaths?: ComponentPaths,
noScopeReset?: boolean,
) => {
if (!components) {
return;
Expand All @@ -53,7 +54,9 @@ export const eachComponentDataAsync = async (
compParent,
)) === true
) {
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
}
if (isComponentNestedDataType(component)) {
Expand All @@ -75,6 +78,7 @@ export const eachComponentDataAsync = async (
local,
component,
compPaths,
noScopeReset,
);
}
} else if (includeAll) {
Expand All @@ -86,13 +90,18 @@ export const eachComponentDataAsync = async (
local,
component,
compPaths,
noScopeReset,
);
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
} else {
if (!includeAll && !shouldProcessComponent(component, row, value)) {
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
}
await eachComponentDataAsync(
Expand All @@ -103,9 +112,12 @@ export const eachComponentDataAsync = async (
local,
component,
compPaths,
noScopeReset,
);
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
} else if (!component.type || getModelType(component) === 'none') {
const info = componentInfo(component);
Expand All @@ -120,6 +132,7 @@ export const eachComponentDataAsync = async (
local,
component,
compPaths,
noScopeReset,
);
}
} else if (info.hasRows) {
Expand All @@ -135,6 +148,7 @@ export const eachComponentDataAsync = async (
local,
component,
compPaths,
noScopeReset,
);
}
}
Expand All @@ -148,12 +162,17 @@ export const eachComponentDataAsync = async (
local,
component,
compPaths,
noScopeReset,
);
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return true;
}
resetComponentScope(component);
if (!noScopeReset) {
resetComponentScope(component);
}
return false;
},
true,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/formUtil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ export function getComponentFromPath(
componentMatches(component, paths || {}, path, dataIndex, matches);
},
includeAll,
false,
undefined,
undefined,
true,
);
} else {
eachComponent(
Expand Down
Loading