Skip to content

Commit b9ebc0a

Browse files
authored
Merge pull request #79 from formio/FIO-8210-fix-nested-form-validation
change filter processor to be more verbose and have compModelType in …
2 parents 5828e5a + 58d6a6f commit b9ebc0a

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/process/filter/__tests__/filter.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ it('Should not filter empty array value for dataGrid component', async () => {
2323
};
2424
const context: any = generateProcessorContext(dataGridComp, data);
2525
filterProcessSync(context);
26-
expect(context.scope.filter).to.deep.equal({'dataGrid': true});
26+
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true}});
2727
});
2828

2929
it('Should not filter empty array value for editGrid component', async () => {
@@ -46,7 +46,7 @@ it('Should not filter empty array value for editGrid component', async () => {
4646
};
4747
const context: any = generateProcessorContext(editGridComp, data);
4848
filterProcessSync(context);
49-
expect(context.scope.filter).to.deep.equal({'editGrid': true});
49+
expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': true}});
5050
});
5151

5252
it('Should not filter empty array value for datTable component', async () => {
@@ -69,5 +69,5 @@ it('Should not filter empty array value for datTable component', async () => {
6969
};
7070
const context: any = generateProcessorContext(dataTableComp, data);
7171
filterProcessSync(context);
72-
expect(context.scope.filter).to.deep.equal({'dataTable': true});
72+
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true}});
7373
});

src/process/filter/index.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@ export const filterProcessSync: ProcessorFnSync<FilterScope> = (context: FilterC
1212
const modelType = Utils.getModelType(component);
1313
switch (modelType) {
1414
case 'dataObject':
15-
scope.filter[absolutePath] = {data: {}};
15+
scope.filter[absolutePath] = {
16+
compModelType: modelType,
17+
include: true,
18+
value: {data: {}}
19+
};
1620
break;
1721
case 'array':
18-
scope.filter[absolutePath] = true;
22+
scope.filter[absolutePath] = {
23+
compModelType: modelType,
24+
include: true,
25+
};
1926
break;
2027
case 'object':
2128
if (component.type !== 'container') {
22-
scope.filter[absolutePath] = true;
29+
scope.filter[absolutePath] = {
30+
compModelType: modelType,
31+
include: true,
32+
};
2333
}
2434
break;
2535
default:
26-
scope.filter[absolutePath] = true;
36+
scope.filter[absolutePath] = {
37+
compModelType: modelType,
38+
include: true,
39+
};
2740
break;
2841
}
2942
}
@@ -37,13 +50,13 @@ export const filterPostProcess: ProcessorFnSync<FilterScope> = (context: FilterC
3750
const { scope, submission } = context;
3851
const filtered = {};
3952
for (const path in scope.filter) {
40-
if (scope.filter[path]) {
53+
if (scope.filter[path].include) {
4154
let value = get(submission?.data, path);
4255
if (isObject(value) && isObject(scope.filter[path])) {
43-
if ((value as any).data) {
44-
value = {...value, ...scope.filter[path], data: (value as any)?.data}
56+
if (scope.filter[path].compModelType === 'dataObject') {
57+
value = {...value, ...scope.filter[path].value, data: (value as any)?.data}
4558
} else {
46-
value = {...value, ...scope.filter[path]}
59+
value = {...value, ...scope.filter[path].value}
4760
}
4861
}
4962
set(filtered, path, value);
+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { ProcessorScope } from "..";
22
export type FilterScope = {
3-
filter: Record<string, any>;
4-
} & ProcessorScope;
3+
filter: Record<string, {
4+
compModelType: string;
5+
include: boolean;
6+
value?: any;
7+
}>;
8+
} & ProcessorScope;

0 commit comments

Comments
 (0)