-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
form validation function runs on on change for onSubmit forms #8799
Comments
Can you please provide a reproduction sandbox? |
@slax57 , if you go to "Create Post" and type in any fields, you will notice that counter at the top is refreshing via "validate function |
It is worth noting that field will not be marked as invalid until submit is pressed; however validate function still runs on each field change, increasing load on REST api server. Also note that changing a different field ( |
Thanks for the sandbox. |
@slax57 react-hook-form works fine. Here is an example - only runs validate onSubmit (see |
@slax57, I also noticed that that the entire form re-renders on each event in any field (onChange and onBlur). See link below that displays validation function run counts and re-render counts. Notice that react-hook-form does not re-render oChange and onBlur. |
Thanks @ns-vpanfilov for the additional info and the sandboxes, that allowed me to reproduce. The following lines in We'll probably need to revert these changes, as we should not subscribe to all form state values upfront, but rather let each child component that needs specific form state values subscribe to them. I'll open a PR, and perform checks against the OSS and EE components to ensure this doesn't break anything. Hopefully it won't break third-party components either. If ever it does, it probably means those components do not follow the RHF rules established here: https://react-hook-form.com/api/useform/formstate/#rules |
I still got this bug, at react-admin ^4.5.1.
|
@slax57 Great. Updated the latest version and the issue gone |
What you were expecting:
I have an async function that validates that email belongs to an active user. Although mode is set to
onSubmit
, the function is executed on change for. I expect validation function to only run on changeWhat happened instead:
Validation function runs on key press (console.log is triggered in the example above)
Environment
The text was updated successfully, but these errors were encountered: