提问人:BATMAN_2008 提问时间:11/16/2023 更新时间:11/16/2023 访问量:21
为什么当我将架构添加到我的表单时出现以下错误: Uncaught (in promise) TypeError: branch is not a function
Why do I get the following error when I am adding schema to my Form: Uncaught (in promise) TypeError: branch is not a function
问:
当我将架构添加到我的表单时,我收到以下错误,错误:
Uncaught (in promise) TypeError: branch is not a function
以下是我添加到表单中的基础架构:yup
export const mySchema = (t) =>
yup.object().shape({
type: yup.string().required("Type is Required"),
gType: yup.string().when("type", {
is: (type) => type === "TYPE1" || type === "TYPE2",
then: (schema) => schema.required("G Type is required"),
}),
identifier: yup.string().when("type", {
is: (type) => {
return (type === "TYPE1" || type === "TYPE2");
},
then: (schema) =>
schema.required("Identifier is required").matches(/^.{13}$/, "Identifier Must be Numeric"),
}),
extension: yup.string().when(["type", "gType"], {
is: (type, gType) => {
return (type === "TYPE2" || gType === "IDTYPE");
},
then: yup.string().required("Extension is required"),
}),
});
该问题主要发生在我想根据 2 个差分字段值和 .但是当我检查这些值时,我能够在 yup 架构中控制台 .log 它们:extension
type
gType
is: (type, gType) => {
console.log("Type : " + type)
console.log("GType : " + gType)
return (type === "TYPE2" || gType === "IDTYPE");
},
但是由于某种原因,我与控制台.log一起收到上述错误。我已经检查了我的表格和字段,并提供了名称和所有内容。如果我从上面的架构中删除,那么一切正常,但添加它失败了。vee-validate
extension
我也尝试获取这样的数组,但这样做我只能得到并且由于某种原因显示为未定义:type
gType
extension: yup.string().when(["type", "gType"], {
is: (values) => values[0] === "TYPE2" || values[1] === "IDTYPE",
then: yup.string().required("Extension is required"),
}),
有人可以告诉我如何解决这个问题吗?
答: 暂无答案
评论