Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

conditional field validation with Yup

validationSchema={yup.object().shape({
    showEmail: yup.boolean(),
    email: yup
      .string()
      .email()
      .when("showEmail", {
        is: true,
        then: yup.string().required("Must enter email address")
      })
  })
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #conditional #field #validation #Yup
ADD COMMENT
Topic
Name
9+5 =