I tried to do the validation using yup with react hook form. When the first checkbox is enabled I want to make the second checkbook required. When the second checkbox is enabled remaining fields should be required.
yup.object().shape({
firstName: yup.string().required(),
age: yup.number().required().positive().integer(),
website: yup.string().url(),
h1: yup.boolean(),
h2: yup.boolean().test("required", "h2 required", function validator(val) {
const { h1 } = this.parent;
return h1;
})
and my codesandbox link is https://codesandbox.io/s/react-hook-form-validationschema-forked-pmcgo?file=/src/index.js:178-471
How to fix this issue