const checkEmailDuplicate = async (email: string): Promise<boolean> => {
const isDuplicate = await emailDuplicate(email);
if (isDuplicate) {
return false;
}
return true;
};
const checkUsernameDuplicate = async (name: string): Promise<boolean> => {
const isDuplicate = await usernameDuplicate(name);
if (isDuplicate) {
return false;
}
return true;
};
const SignupSchema = Yup.object<SignupFormValues>().shape({
user_email: Yup.string()
.required("Please enter an email.")
.email("Please enter a valid email.")
**.test('checkDupEmail', 'Checking email duplication...', emailDuplicate),**
user_name: Yup.string()
.required("Please enter a name.")
.min(2, "Please enter at least 2 characters for the name.")
.max(25, "Please limit the name to 25 characters.")
.matches(/^[a-zA-Z0-9]+$/, "Please use letters and numbers only.")
**.test('checkDupName', 'Checking name duplication...', usernameDuplicate),**
user_password: Yup.string()
.required("Please enter a password.")
.min(8, "Please enter at least 8 characters."),
confirm_user_password: Yup.string()
.required("Please enter password confirmation.")
.oneOf([Yup.ref('user_password')], "Password does not match.")
});
I’m trying to use the test() to check for duplicates of user_email and user_name during the validation process. However, using the test method on both user_email and user_name at the same time causes a problem. The test() written after (user_name in my Yup schema) is not executed.
If I code them separately, it works fine, but if I code them both at the same time, I get this problem.
This is the content of the warning message
Formik.tsx:255 Warning: An unhandled error was caught during validation in <Formik validationSchema />
Formik.tsx:834 Warning: An unhandled error was caught from submitForm()
ontothenextlevel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.