Skip to content

Commit

Permalink
remove tags from data if value is null (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenMasterJacob20011 authored Jan 14, 2025
1 parent 49ab979 commit 50be7ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/process/normalize/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ProcessorContext,
ProcessorScope,
DayComponent,
TagsComponent,
} from 'types';
import { normalizeProcessSync } from '../';
import { generateProcessorContext } from '../../__tests__/fixtures/util';
Expand Down Expand Up @@ -338,4 +339,21 @@ describe('Normalize processor', function () {
normalizeProcessSync(context);
expect({ day: '01/2025' }).to.deep.equal({ day: '01/2025' });
});

it('Should remove the tag component from the submission object if data is set to null', async function () {
const tagsComponent: TagsComponent = {
input: true,
delimeter: '',
maxTags: 1,
storeas: '',
type: 'tags',
key: 'tags',
};
const data = {
tags: null,
};
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(tagsComponent, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({});
});
});
3 changes: 3 additions & 0 deletions src/process/normalize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ export const normalizeProcessSync: ProcessorFnSync<NormalizeScope> = (context) =
scope.normalize[path].normalized = true;
} else if (isTagsComponent(component)) {
set(data, path, normalizeTagsComponentValue(component, value));
if (data[path] === null) {
delete data[path];
}
scope.normalize[path].normalized = true;
} else if (isTextFieldComponent(component)) {
set(data, path, normalizeTextFieldComponentValue(component, defaultValues, value, path));
Expand Down

0 comments on commit 50be7ac

Please sign in to comment.