【发布时间】:2021-11-01 21:22:21
【问题描述】:
我如何验证至少需要两个字段?
请在此处检查代码框Click Here
const validationSearch = yup.object().shape({
instagramProfileId: yup
.string()
.when(["$tiktokProfileId", "$youtubeProfileId"], {
is: (tiktokProfileId, youtubeProfileId) =>
tiktokProfileId && youtubeProfileId,
then: yup.string().notRequired(),
otherwise: yup.string().required()
}),
tiktokProfileId: yup
.string()
.when(["$instagramProfileId", "$youtubeProfileId"], {
is: (instagramProfileId, youtubeProfileId) =>
instagramProfileId && youtubeProfileId,
then: yup.string().notRequired(),
otherwise: yup.string().required()
}),
youtubeProfileId: yup
.string()
.when(["$instagramProfileId", "$tiktokProfileId"], {
is: (instagramProfileId, tiktokProfileId) =>
instagramProfileId && tiktokProfileId,
then: yup.string().notRequired(),
otherwise: yup.string().required()
})
});
【问题讨论】:
标签: reactjs ecmascript-6 react-hooks yup