Skip to content

Commit

Permalink
Merge pull request #115 from formio/FIO-8597-Empty-array-value-for-a-…
Browse files Browse the repository at this point in the history
…number-component-with-multiple-values-enabled

FIO-8597: fixed an issue with an empty array value for a number component with multiple values enabled
  • Loading branch information
brendanbond authored Jul 5, 2024
2 parents f8395af + 5ff5eb9 commit c7cda57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/process/validation/rules/__tests__/validateNumber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ it('Validating a multiple number with a blank value will return null', async ()
const result = await validateMultiple(context);
expect(result).to.equal(null);
});

it('Validating a multiple number with an empty array value will return null', async () => {
const component = {
...simpleNumberField,
multiple: true
};
const data = {
component: [],
};
const context = generateProcessorContext(component, data);
const result = await validateMultiple(context);
expect(result).to.equal(null);
});
3 changes: 3 additions & 0 deletions src/process/validation/rules/validateNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export const shouldValidate = (context: ValidationContext) => {
if (!value) {
return false;
}
if (component.multiple && Array.isArray(value) && value.length === 0) {
return false;
}
if (!isValidatableNumberComponent(component)) {
return false;
}
Expand Down

0 comments on commit c7cda57

Please sign in to comment.