mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
test min and max manuel because with string min and max don't work this way with yup
This commit is contained in:
parent
14682e8085
commit
bc213707d7
@ -165,7 +165,6 @@ const validationSchema = computed(() => {
|
||||
.required('form.validation.contributionMemo.required'),
|
||||
hours: string()
|
||||
.typeError({ key: 'form.validation.hours.typeError', values: { min: 0.01, max: maxHours } })
|
||||
.required()
|
||||
.transform((currentValue) =>
|
||||
!currentValue || typeof currentValue !== 'string'
|
||||
? currentValue
|
||||
@ -179,18 +178,22 @@ const validationSchema = computed(() => {
|
||||
return /^\d+(\.\d{0,2})?$/.test(value.toString())
|
||||
})
|
||||
// min and max are not working with string, so we need to do it manually
|
||||
.test('min-hours', 'form.validation.hours.min', (value) => {
|
||||
if (value === undefined || value === null || Number(value).isNaN()) {
|
||||
.test('min-hours', { key: 'form.validation.hours.min', values: { min: 0.01 } }, (value) => {
|
||||
if (value === undefined || value === null || Number.isNaN(parseFloat(value))) {
|
||||
return false
|
||||
}
|
||||
return parseFloat(value) >= 0.01
|
||||
})
|
||||
.test('max-hours', 'form.validation.hours.max', (value) => {
|
||||
if (value === undefined || value === null || Number(value).isNaN()) {
|
||||
return false
|
||||
}
|
||||
return parseFloat(value) <= maxHours
|
||||
}),
|
||||
.test(
|
||||
'max-hours',
|
||||
{ key: 'form.validation.hours.max', values: { max: maxHours } },
|
||||
(value) => {
|
||||
if (value === undefined || value === null || Number.isNaN(parseFloat(value))) {
|
||||
return false
|
||||
}
|
||||
return parseFloat(value) <= maxHours
|
||||
},
|
||||
),
|
||||
amount: number().min(0.01).max(maxAmounts),
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user