AsZ*_*Zik 1 reactjs react-native yup formik
我收到上述错误。不知道该物体发生了什么。下面是我的对象。
export const loginValidator = yup.object({
login: yup.string().when('password', {
is: (v) => v < 9999 && v > 999,
then: yup.string().required('Phone No is required').matches(phoneRegExp, 'Must be 10 digits'),
otherwise: yup.string().email().required('Email is required'),
}),
password: yup.string().when('login', {
is: (m) => phoneRegExp.test(m),
then: yup
.string()
.required('Pin is Required')
.matches(/^[0-9]+$/, 'Must be only digits')
.min(5, 'Must be exactly 5 digits')
.max(5, 'Must be exactly 5 digits'),
otherwise: yup.string().required('password is required'),
}),
});
Run Code Online (Sandbox Code Playgroud)
我得到的错误
Error: Cyclic dependency, node was:"password"
Run Code Online (Sandbox Code Playgroud)
这是怎么回事谢谢!!
为了避免循环依赖,必须将这些值添加到 yup.
[['login', 'password']]
Run Code Online (Sandbox Code Playgroud)
例子,
export const loginValidator = yup.object().shape(
{
login: yup.string().when('password', {
is: (v) => v < 100000,
then: yup.string().required('Phone No is required').matches(phoneRegExp, 'Must be 10 digits'),
otherwise: yup.string().email().required('Email is required'),
}),
password: yup.string().when('login', {
is: (m) => phoneRegExp.test(m),
then: yup
.string()
.required('Pin is Required')
.matches(/^[0-9]+$/, 'Must be only digits')
.min(5, 'Must be exactly 5 digits')
.max(5, 'Must be exactly 5 digits'),
otherwise: yup.string().required('password is required'),
}),
},
[['login', 'password']]
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2882 次 |
| 最近记录: |