remove required validation on input field (if I entered some text in another input field) .I created input fields (two input field )from json .Initially both are required.But if user enter "hello" in first field I want to remove required check from second input field.I used watch and onchange I checked the value of first field .but how to remove required ?I tried by using unregister but still not working
const onChange = e => {
console.log(e.target.name);
if (e.target.name == "agencyName") {
if (agencyName == "hello") {
//remove required
unregister({ required: false, name: "contactPerson" });
}
}
};
here is my code https://codesandbox.io/s/react-hook-form-watch-unir2
API link
contactPersonbut how I will unregistered ? - user944513requiredon contact, all too complicated. You need a validation expression that incorporates the value of agency. - Richard Matsen