Javascript 当条件适用时,使用yup覆盖表单中的值
我正在尝试构建一个Javascript 当条件适用时,使用yup覆盖表单中的值,javascript,formik,yup,Javascript,Formik,Yup,我正在尝试构建一个yup验证模式,但我不知道如何在每次值与模式不匹配时将其转换为默认值 我试图检查的是大于0的值和未定义的值,因此需要此表单值,否则我想将其设置为空字符串 这是我的代码: reason: string() .when('value', { is: val => Boolean(val), then: string().required('This field is required'), otherwise: string().transform((value
yup
验证模式,但我不知道如何在每次值与模式不匹配时将其转换为默认值
我试图检查的是大于0的值和未定义的值,因此需要此表单值,否则我想将其设置为空字符串
这是我的代码:
reason: string()
.when('value', {
is: val => Boolean(val),
then: string().required('This field is required'),
otherwise: string().transform((value) => value ? value : '')
})
非常感谢