[Vuejs]-Vuejs 3 yup type according validations

0👍

Add memberType to the validation then you can do something like this:

const validationSchema = Yup.object().shape({
  memberType: Yup.string().required(),
  phone: Yup
    .string()
    .trim()
    .label("Phone")
    .when("memberType", {
        is: "individual",
        then: Yup.string().required("Must enter phone number")
     }),
  tax: Yup
    .string()
    .trim()
    .label("Tax")
    .when("memberType", {
        is: "corporate",
        then: Yup.string().required("Must enter tax number")
     }),
});

Leave a comment