From e4127b89ccde1681644ee7e9af9a33f2728c6f34 Mon Sep 17 00:00:00 2001 From: Sampo Tawast Date: Thu, 14 Dec 2023 10:24:51 +0200 Subject: [PATCH] fix: yup fails to validate 0 as min value --- .../forms/application/step2/utils/validation.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/benefit/applicant/src/components/applications/forms/application/step2/utils/validation.ts b/frontend/benefit/applicant/src/components/applications/forms/application/step2/utils/validation.ts index b6ef808722..b503a8131d 100644 --- a/frontend/benefit/applicant/src/components/applications/forms/application/step2/utils/validation.ts +++ b/frontend/benefit/applicant/src/components/applications/forms/application/step2/utils/validation.ts @@ -113,7 +113,9 @@ export const getValidationSchema = ( max: param.max, key: VALIDATION_MESSAGE_KEYS.NUMBER_MAX, })) - .transform((_value, originalValue) => getNumberValue(originalValue)) + .transform((_value, originalValue) => + originalValue ? getNumberValue(originalValue) : null + ) .typeError(t(VALIDATION_MESSAGE_KEYS.NUMBER_INVALID)) .required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)), [EMPLOYEE_KEYS.MONTHLY_PAY]: Yup.number() @@ -125,7 +127,9 @@ export const getValidationSchema = ( max: param.max, key: VALIDATION_MESSAGE_KEYS.NUMBER_MAX, })) - .transform((_value, originalValue) => getNumberValue(originalValue)) + .transform((_value, originalValue) => + originalValue ? getNumberValue(originalValue) : null + ) .typeError(t(VALIDATION_MESSAGE_KEYS.NUMBER_INVALID)) .required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)), [EMPLOYEE_KEYS.OTHER_EXPENSES]: Yup.number() @@ -137,7 +141,9 @@ export const getValidationSchema = ( max: param.max, key: VALIDATION_MESSAGE_KEYS.NUMBER_MAX, })) - .transform((_value, originalValue) => getNumberValue(originalValue)) + .transform((_value, originalValue) => + originalValue ? getNumberValue(originalValue) : null + ) .typeError(t(VALIDATION_MESSAGE_KEYS.NUMBER_INVALID)) .required(t(VALIDATION_MESSAGE_KEYS.REQUIRED)), [EMPLOYEE_KEYS.COLLECTIVE_BARGAINING_AGREEMENT]: Yup.string().required(