Check if a single field isValid #228
Answered
by
airjp73
piotrkulpinski
asked this question in
Q&A
-
Hi, Is there a way to check if a given field is valid without first validating the whole form? I don't want to display any errors, just conditionally check validity of single field. |
Beta Was this translation helpful? Give feedback.
Answered by
airjp73
Jan 16, 2023
Replies: 1 comment 1 reply
-
I think the only way to do this without actually validating the field is to go around the library a bit rather than going through it. const context = useFormContext();
async function checkFieldValidity() {
// This check might not be 100% correct but should be close
const result = await validator.validateField(context.getValues(), 'myField');
const isValid = !!result.error;
return isValid;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
piotrkulpinski
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the only way to do this without actually validating the field is to go around the library a bit rather than going through it.