Skip to content

Commit

Permalink
fix: yup fails to validate 0 as min value
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtawast committed Dec 14, 2023
1 parent 43810e0 commit e4127b8
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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(
Expand Down

0 comments on commit e4127b8

Please sign in to comment.