当尝试使用 Yup 库进行验证时,以下函数中会抛出错误“branch is not a function”(我已注释掉 schema.validate 函数,在这种情况下我的代码可以正常工作,但使用 schema 则无法正常工作):
const schema = Yup.object({
boundary: Yup.string().required('Boundary is required'),
boundaryConstructionDate: Yup.string().when('boundary', {
is: (value) => value === 'yes',
then: Yup.string().required('Boundary construction date is required'),
otherwise: Yup.string(),
}),
toilet: Yup.string().required('Toilet is required'),
toiletConstructionDate: Yup.string().when('toilet', {
is: (value) => value === 'yes',
then: Yup.string().required('Toilet construction date is required'),
otherwise: Yup.string(),
}),
payjal: Yup.string().required('Payjal is required'),
ramp: Yup.string().required('Ramp is required'),
rampConstructionDate: Yup.string().when('ramp', {
is: (value) => value === 'yes',
then: Yup.string().required('Ramp construction date …Run Code Online (Sandbox Code Playgroud)