Skip to content

Commit

Permalink
Merge pull request #76 from formio/FIO-8177-fix-unsetting-empty-array…
Browse files Browse the repository at this point in the history
…-values

Fio 8177 fix unsetting empty array values
  • Loading branch information
brendanbond authored Apr 9, 2024
2 parents 3bf8538 + b78fcc5 commit 62ed3c7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/process/filter/__tests__/filter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { expect } from 'chai';

import { filterProcessSync } from '../';
import { generateProcessorContext } from '../../__tests__/fixtures/util';

it('Should not filter empty array value for dataGrid component', async () => {
const dataGridComp = {
type: 'datagrid',
key: 'dataGrid',
input: true,
path: 'dataGrid',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
dataGrid: []
};
const context: any = generateProcessorContext(dataGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataGrid': true});
});

it('Should not filter empty array value for editGrid component', async () => {
const editGridComp = {
type: 'editgrid',
key: 'editGrid',
input: true,
path: 'editGrid',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
editGrid: []
};
const context: any = generateProcessorContext(editGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'editGrid': true});
});

it('Should not filter empty array value for datTable component', async () => {
const dataTableComp = {
type: 'datatable',
key: 'dataTable',
input: true,
path: 'dataTable',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
dataTable: []
};
const context: any = generateProcessorContext(dataTableComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataTable': true});
});
1 change: 1 addition & 0 deletions src/process/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const filterProcessSync: ProcessorFnSync<FilterScope> = (context: FilterC
scope.filter[absolutePath] = {data: {}};
break;
case 'array':
scope.filter[absolutePath] = true;
break;
case 'object':
if (component.type !== 'container') {
Expand Down

0 comments on commit 62ed3c7

Please sign in to comment.