-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
canSubmit
is always true
on first render of form
#723
Comments
Hey! The current behavior in the example seems correct to me, the validator is triggered What you're trying to achieve might be validating With that said, if we agree that An alternative option could be to manually run |
** I figured out the solution for
|
Not sure what the answer is here but I also encountered this same behaviour and find it confusing. I validate my fields I would've expected that disabling the "Submit" button based on |
I'm having the same issue. I'm trying to run validations at Hoping for a fix soon... 🙏 |
Opinion: <Field
name="resource"
validators={{
onMount: myValidator,
onChange: myValidator,
}}
children={field => (
<MyCustomInputComponent
//...other field props
errors={field.state.meta.isTouched ? field.state.meta.errors : []}
/>
)}
/> Then just use the same validator for onChange and onMount. The fact that you have to specify the same function for onChange and onMount is a bit annoying for sure. |
Correction: The above strategy wont work because onMount validator seems to mark the field as touched. I definitely think this is a bug. @Balastrong opinion here? |
Hey everyone, an update on this issue! As mentioned at the beginning, it's correct that if there's only the The recommended way is to run validation One tiny detail remains, to have a first validation when the component mounts and keep validating when values are changed, you have to set the same validator to both Also, sorry if this took so long and thanks for all the feedback and examples! |
Describe the bug
I am using a form with the
zodValidator
and have several field-level validations. On the first render thecanSubmit
property is true even though several fields are invalid. After changing the first input the validations run andcanSubmit
is invalid.Your minimal, reproducible example
https://tanstack.com/form/latest/docs/framework/react/examples/zod
Steps to reproduce
Submit
button is enabled even though the firstName has a minLength validation of 3Submit
button is disabled until all the validations are correctExpected behavior
I would expect that the
canSubmit
property considers all validations on the first render and shows a disabledSubmit
button from the start instead of changing from enabled to disabled after typing one letter and going back to enabled after all validations are correct.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: MacOS
Browser: Arc
TanStack Form adapter
react-form
TanStack Form version
0.20.2
TypeScript version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: