Skip to content

Commit

Permalink
Merge pull request #181 from formio/FIO-9261-fixed-multiple-value-val…
Browse files Browse the repository at this point in the history
…idation

FIO-9261: fixed an issue where empty multiple value for url and datetime causes validation errors
  • Loading branch information
brendanbond authored Oct 30, 2024
2 parents 92e29d1 + 29ff4ec commit 51dd947
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4040,6 +4040,97 @@ describe('Process Tests', function () {
});
});

it('Should not return errors for empty multiple values for url and dateTime', function () {
const form = {
_id: '671f7fbeaf87b0e2a26e4212',
title: 'form2',
name: 'form2',
path: 'form2',
type: 'form',
display: 'form',
components: [
{
label: 'Url',
applyMaskOn: 'change',
tableView: true,
multiple: true,
validateWhenHidden: false,
key: 'url',
type: 'url',
input: true,
},
{
label: 'Date / Time',
tableView: false,
datePicker: {
disableWeekends: false,
disableWeekdays: false,
},
multiple: true,
enableMinDateInput: false,
enableMaxDateInput: false,
validateWhenHidden: false,
key: 'dateTime',
type: 'datetime',
input: true,
widget: {
type: 'calendar',
displayInTimezone: 'viewer',
locale: 'en',
useLocaleSettings: false,
allowInput: true,
mode: 'single',
enableTime: true,
noCalendar: false,
format: 'yyyy-MM-dd hh:mm a',
hourIncrement: 1,
minuteIncrement: 1,
time_24hr: false,
minDate: null,
disableWeekends: false,
disableWeekdays: false,
maxDate: null,
},
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false,
},
],
created: '2024-10-28T12:12:46.715Z',
modified: '2024-10-29T10:18:00.534Z',
};

const submission = {
data: { url: [], dateTime: [], submit: true },
state: 'submitted',
};

const errors: any = [];
const conditionals: any = [];
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: { errors, conditionals },
config: {
server: true,
},
};

processSync(context);
submission.data = context.data;
context.processors = ProcessTargets.evaluator;
processSync(context);
assert.deepEqual(context.scope.errors.length, 0);
});

describe('Required component validation in nested form in DataGrid/EditGrid', function () {
const nestedForm = {
key: 'form',
Expand Down
5 changes: 5 additions & 0 deletions src/process/validation/rules/validateDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const shouldValidate = (context: ValidationContext) => {
if (!value || !isValidatable(component)) {
return false;
}

if (component.multiple && Array.isArray(value) && value.length === 0) {
return false;
}

return true;
};

Expand Down
5 changes: 5 additions & 0 deletions src/process/validation/rules/validateUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const shouldValidate = (context: ValidationContext) => {
if (!isUrlComponent(component)) {
return false;
}

if (component.multiple && Array.isArray(value) && value.length === 0) {
return false;
}

if (!value) {
return false;
}
Expand Down

0 comments on commit 51dd947

Please sign in to comment.