我正在使用 yup 和 formik 来管理我的表单。我使用 yup 进行表单验证。我面临的问题是:假设我有三个字段fieldA
, fieldB
and fieldC
。验证是:fieldA
+ fieldB
必须等于fieldC
。这是我所做的使用.when
但我无法添加[string, string, string]
到第二个参数yup.object().shape
功能。
yup.object().shape({
fieldC: yup.number().nullable(),
fieldA: yup.number().nullable()
.when(['fieldA','fieldB', 'fieldC'], {
is: (fieldA, fieldB, fieldC)=> // my condition //,
then: // schemma //,
otherWise: // schemma //,
}),
fieldB: yup.number().nullable()
.when(['fieldA','fieldB', 'fieldC'], {
is: (fieldA, fieldB, fieldC)=> // my condition //,
then: // schemma //,
otherWise: // schemma //,
}),
}, [['fieldA', 'fieldB','fieldC' ]]);