From 547aa3ed65744b4fece858363e47b0ce062c3562 Mon Sep 17 00:00:00 2001 From: Vitaly Vasin Date: Mon, 28 Aug 2023 11:58:53 +0200 Subject: [PATCH 1/2] feat: ignore minimum check when a number field is empty --- src/lib/kit/validators/__tests__/validators.test.ts | 1 + src/lib/kit/validators/validators.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/kit/validators/__tests__/validators.test.ts b/src/lib/kit/validators/__tests__/validators.test.ts index 3c7742dd..7dd1db4e 100644 --- a/src/lib/kit/validators/__tests__/validators.test.ts +++ b/src/lib/kit/validators/__tests__/validators.test.ts @@ -83,6 +83,7 @@ describe('kit/validators/validators', () => { spec.minimum = 100.5; expect(getNumberValidator({ignoreMinimumCheck: true})(spec, '1.01')).toBe(false); + expect(validator(spec, '')).toBe(false); expect(validator(spec, '1.01')).toBe(ErrorMessages.minNumber(spec.minimum)); expect(validator(spec, 1.01)).toBe(ErrorMessages.minNumber(spec.minimum)); expect(validator(spec, 101)).toBe(false); diff --git a/src/lib/kit/validators/validators.ts b/src/lib/kit/validators/validators.ts index 403562fd..c81e61d5 100644 --- a/src/lib/kit/validators/validators.ts +++ b/src/lib/kit/validators/validators.ts @@ -137,7 +137,8 @@ export const getNumberValidator = (params: GetNumberValidatorParams = {}) => { if ( !ignoreMinimumCheck && _.isNumber(spec.minimum) && - ((stringValue.length && spec.minimum > Number(stringValue)) || !stringValue.length) + stringValue.length && + spec.minimum > Number(stringValue) ) { return ErrorMessages.minNumber(spec.minimum); } From 465055ce094eb4f2786f48598b23b83178675198 Mon Sep 17 00:00:00 2001 From: Vitaly Vasin Date: Mon, 28 Aug 2023 17:06:24 +0200 Subject: [PATCH 2/2] fixup! feat: ignore minimum check when a number field is empty --- .../core/components/Form/__tests__/DynamicField.test.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib/core/components/Form/__tests__/DynamicField.test.tsx b/src/lib/core/components/Form/__tests__/DynamicField.test.tsx index 674ea467..9a26906e 100644 --- a/src/lib/core/components/Form/__tests__/DynamicField.test.tsx +++ b/src/lib/core/components/Form/__tests__/DynamicField.test.tsx @@ -177,7 +177,6 @@ test('Form/hooks/DynamicField', () => { const errors = { name: false, - 'name.id': ErrorMessages.minNumber(10), 'name.name': ErrorMessages.REQUIRED, 'name.description': ErrorMessages.REQUIRED, 'name.settings': ErrorMessages.REQUIRED, @@ -213,7 +212,6 @@ test('Form/hooks/DynamicField', () => { const errors1 = { name: false, - 'name.id': ErrorMessages.minNumber(10), 'name.name': ErrorMessages.REQUIRED, 'name.description': ErrorMessages.REQUIRED, 'name.settings': ErrorMessages.REQUIRED, @@ -250,7 +248,6 @@ test('Form/hooks/DynamicField', () => { const errors2 = { name: false, - 'name.id': ErrorMessages.minNumber(10), 'name.name': ErrorMessages.REQUIRED, 'name.description': ErrorMessages.REQUIRED, 'name.settings': ErrorMessages.REQUIRED, @@ -322,7 +319,7 @@ test('Form/hooks/DynamicField', () => { const errors4 = { name: false, - 'name.id': ErrorMessages.minNumber(10), + 'name.id': false, 'name.name': ErrorMessages.REQUIRED, 'name.description': ErrorMessages.REQUIRED, 'name.settings': ErrorMessages.REQUIRED, @@ -372,7 +369,7 @@ test('Form/hooks/DynamicField', () => { const errors5 = { name: false, - 'name.id': ErrorMessages.minNumber(10), + 'name.id': false, 'name.name': ErrorMessages.REQUIRED, 'name.description': ErrorMessages.REQUIRED, 'name.settings': ErrorMessages.REQUIRED,