How am I able to know whether a form has been validated or not? #13283
-
|
I can see there's a My requirement is:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi 👋 isSubmitted only tells you that a submit attempt happened — it does not guarantee the form is valid. If you want to know whether validation has run and control when to show error/success state, you can combine: const { formState: { isSubmitted, isValid, errors } } = useForm({ Key points: isSubmitted → becomes true after submit attempt (even if invalid) isValid → true only when there are no validation errors errors → contains current validation errors If your requirement is: “Only show error/success state after validation” You can do something like: const showValidationState = isSubmitted; {showValidationState && errors.name && Error} Or for success state: {showValidationState && !errors.name && Success} If you want to know whether the submission was successful (no errors), you can use: formState.isSubmitSuccessful That’s usually the cleanest signal after submit. Let me know if this resolves your use case 👍 |
Beta Was this translation helpful? Give feedback.
Hi 👋
isSubmitted only tells you that a submit attempt happened — it does not guarantee the form is valid.
If you want to know whether validation has run and control when to show error/success state, you can combine:
const { formState: { isSubmitted, isValid, errors } } = useForm({
mode: "onSubmit", // important
});
Key points:
isSubmitted → becomes true after submit attempt (even if invalid)
isValid → true only when there are no validation errors
errors → contains current validation errors
If your requirement is:
“Only show error/success state after validation”
You can do something like:
const showValidationState = isSubmitted;
{showValidationState && errors.name && Error}
Or for success …