Skip to content

Commit

Permalink
Merge pull request #79 from formio/FIO-8210-fix-nested-form-validation
Browse files Browse the repository at this point in the history
change filter processor to be more verbose and have compModelType in …
  • Loading branch information
travist authored Apr 12, 2024
2 parents 5828e5a + 58d6a6f commit b9ebc0a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/process/filter/__tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it('Should not filter empty array value for dataGrid component', async () => {
};
const context: any = generateProcessorContext(dataGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataGrid': true});
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true}});
});

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

it('Should not filter empty array value for datTable component', async () => {
Expand All @@ -69,5 +69,5 @@ it('Should not filter empty array value for datTable component', async () => {
};
const context: any = generateProcessorContext(dataTableComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataTable': true});
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true}});
});
29 changes: 21 additions & 8 deletions src/process/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,31 @@ export const filterProcessSync: ProcessorFnSync<FilterScope> = (context: FilterC
const modelType = Utils.getModelType(component);
switch (modelType) {
case 'dataObject':
scope.filter[absolutePath] = {data: {}};
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
value: {data: {}}
};
break;
case 'array':
scope.filter[absolutePath] = true;
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
break;
case 'object':
if (component.type !== 'container') {
scope.filter[absolutePath] = true;
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
}
break;
default:
scope.filter[absolutePath] = true;
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
break;
}
}
Expand All @@ -37,13 +50,13 @@ export const filterPostProcess: ProcessorFnSync<FilterScope> = (context: FilterC
const { scope, submission } = context;
const filtered = {};
for (const path in scope.filter) {
if (scope.filter[path]) {
if (scope.filter[path].include) {
let value = get(submission?.data, path);
if (isObject(value) && isObject(scope.filter[path])) {
if ((value as any).data) {
value = {...value, ...scope.filter[path], data: (value as any)?.data}
if (scope.filter[path].compModelType === 'dataObject') {
value = {...value, ...scope.filter[path].value, data: (value as any)?.data}
} else {
value = {...value, ...scope.filter[path]}
value = {...value, ...scope.filter[path].value}
}
}
set(filtered, path, value);
Expand Down
8 changes: 6 additions & 2 deletions src/types/process/filter/FilterScope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ProcessorScope } from "..";
export type FilterScope = {
filter: Record<string, any>;
} & ProcessorScope;
filter: Record<string, {
compModelType: string;
include: boolean;
value?: any;
}>;
} & ProcessorScope;

0 comments on commit b9ebc0a

Please sign in to comment.