From 29ff4ecfb5eacfa2663c71efcfcf7aa87c5f87f1 Mon Sep 17 00:00:00 2001 From: "ICX\\Tatsiana.Hashtold" Date: Tue, 29 Oct 2024 16:37:48 +0300 Subject: [PATCH] FIO-9261: fixed an issue where empty multiple value for url and datetime couses validation errors --- src/process/__tests__/process.test.ts | 91 ++++++++++++++++++++ src/process/validation/rules/validateDate.ts | 5 ++ src/process/validation/rules/validateUrl.ts | 5 ++ 3 files changed, 101 insertions(+) diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 29a80fa5..da0feae8 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -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', diff --git a/src/process/validation/rules/validateDate.ts b/src/process/validation/rules/validateDate.ts index ecea692d..fe7e7b25 100644 --- a/src/process/validation/rules/validateDate.ts +++ b/src/process/validation/rules/validateDate.ts @@ -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; }; diff --git a/src/process/validation/rules/validateUrl.ts b/src/process/validation/rules/validateUrl.ts index 1dacc8de..0a4a9a52 100644 --- a/src/process/validation/rules/validateUrl.ts +++ b/src/process/validation/rules/validateUrl.ts @@ -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; }