大家好,我有以下验证:
const questionAddValidation = Yup.object().shape({
questions: Yup.array().of(
Yup.object({
question: Yup.string().required().min(100)
level: Yup.string().required().when("question", {
is: (value) => value.length > 0,
then: Yup.string().required(),
}),
answers: Yup.array().of(
Yup.object({
answer: Yup.string().required().min(1).when("question", {
is: (value) => value && value.length > 0,
then: Yup.string().required(),
}),
})
),
})
),我想做的是,如果用户将输入其他输入的question输入的东西,应该工作的required()方法。
我试着这样做:
is: (value) => value.length > 0但是它不工作,Unhandled Rejection (TypeError): Cannot read property 'length' of undefined你能帮我解决这个问题吗?
发布于 2021-06-24 19:23:35
您只需在when之前删除required()
level: Yup.string().when("question", {
is: (value) => value.length > 0,
then: Yup.string().required(),
}),https://stackoverflow.com/questions/68114654
复制相似问题