Setting Custom Errors in Custom Resolver #5597
-
Is there a way for me to insist that my form updates all the errors on every validate instead of just the error for the field that was being modified? I have two password fields that need to match each other. The error message only shows up on the second field, and we have our validation mode set to Here's my problems:
Code Sandbox: https://codesandbox.io/s/elastic-panini-hqss8 Steps to reproduce what I'm doing:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Thanks for the feedback above. It's a valid one. Let me explain the reason behind a such design. WhyRHF focus on a single input at a time to provide the best performance to your form, in your use case above is a dependency validation. This explains why the input didn't render the correct errors object as your validation focus is at Input A, while you want to show an error message for Input B. I have considered this problem for a while now, there isn't a perfect solution on the table. If we display all the errors message, then we would lose fine control on when and what to re-render. for example, when the whole form is mounted, the entire form is full of errors (if there are no SolutionYou can trigger validation for your depend on validation, so the correct "associated" error message will be displaced. |
Beta Was this translation helpful? Give feedback.
Thanks for the feedback above. It's a valid one. Let me explain the reason behind a such design.
Why
RHF focus on a single input at a time to provide the best performance to your form, in your use case above is a dependency validation. This explains why the input didn't render the correct errors object as your validation focus is at Input A, while you want to show an error message for Input B.
I have considered this problem for a while now, there isn't a perfect solution on the table. If we display all the errors message, then we would lose fine control on when and what to re-render. for example, when the whole form is mounted, the entire form is full of errors (if there are no
defaultValues