From d45b496d98320746b7ed5111173a644af276f67e Mon Sep 17 00:00:00 2001 From: "Maria.Golomb" Date: Fri, 27 Sep 2024 15:28:47 +0200 Subject: [PATCH 1/2] FIO-9086: use for validation only dataFormat (data storage format) --- src/process/validation/rules/__tests__/validateTime.test.ts | 3 ++- src/process/validation/rules/validateTime.ts | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/process/validation/rules/__tests__/validateTime.test.ts b/src/process/validation/rules/__tests__/validateTime.test.ts index 6ec05331..ae9adf7c 100644 --- a/src/process/validation/rules/__tests__/validateTime.test.ts +++ b/src/process/validation/rules/__tests__/validateTime.test.ts @@ -10,7 +10,8 @@ const timeField: TimeComponent = { key: 'time', label: 'Time', input: true, - dataFormat: 'HH:mm:ss' + dataFormat: 'HH:mm:ss', + format: 'HH:mm' }; it('Should validate a time component with a valid time value', async () => { diff --git a/src/process/validation/rules/validateTime.ts b/src/process/validation/rules/validateTime.ts index 047439e0..653f5cb1 100644 --- a/src/process/validation/rules/validateTime.ts +++ b/src/process/validation/rules/validateTime.ts @@ -28,10 +28,7 @@ export const validateTimeSync: RuleFnSync = (context: ValidationContext) => { } try { if (!value || isComponentDataEmpty(component, data, path)) return null; - // Server side evaluations of validity should use the "dataFormat" vs the "format" which is used on the client. - const format = config?.server ? - ((component as TimeComponent).dataFormat || 'HH:mm:ss') : - ((component as TimeComponent).format || 'HH:mm'); + const format = (component as TimeComponent).dataFormat || 'HH:mm:ss'; const isValid = dayjs(String(value), format, true).isValid(); return isValid ? null : new FieldError('time', context); } From 2c3ab48c9f2eb856d391afd45974db9d84e2c0f9 Mon Sep 17 00:00:00 2001 From: "Maria.Golomb" Date: Wed, 2 Oct 2024 15:46:12 +0200 Subject: [PATCH 2/2] FIO-9086: autotests --- src/process/validation/__tests__/Validator.test.ts | 3 ++- src/process/validation/__tests__/fixtures/forms.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/process/validation/__tests__/Validator.test.ts b/src/process/validation/__tests__/Validator.test.ts index 0f9331ff..35810ae6 100644 --- a/src/process/validation/__tests__/Validator.test.ts +++ b/src/process/validation/__tests__/Validator.test.ts @@ -15,6 +15,7 @@ it('Validator will throw the correct errors given a flat components array', asyn email: 'brendanb', url: 'htpigoogle', inputMask: 'hello, world', + time: ['12:00:00', '11:00'], // one of the values is provided in incorrect format (format instead dataFormat) submit: false, }; for (let component of simpleForm.components) { @@ -34,5 +35,5 @@ it('Validator will throw the correct errors given a flat components array', asyn errors = [...errors, ...scope.errors.map((error) => error.errorKeyOrMessage)]; } } - expect(errors).to.have.length(6); + expect(errors).to.have.length(7); }); diff --git a/src/process/validation/__tests__/fixtures/forms.ts b/src/process/validation/__tests__/fixtures/forms.ts index e6a72e0e..37717dcc 100644 --- a/src/process/validation/__tests__/fixtures/forms.ts +++ b/src/process/validation/__tests__/fixtures/forms.ts @@ -2290,6 +2290,15 @@ export const simpleForm = { id: 'e8vls3a', keyModified: true, }, + { + label: 'Time', + type: 'time', + key: 'time', + input: true, + dataFormat: 'HH:mm:ss', + format: 'HH:mm', + multiple: true, + }, { type: 'button', label: 'Submit', @@ -2297,7 +2306,7 @@ export const simpleForm = { disableOnInvalid: true, input: true, tableView: false, - }, + } ], settings: {}, properties: {},