Replies: 3 comments 2 replies
-
Is this something similar to what you're looking for? const form = useForm({
validators: {
onChange: ({ formApi }) =>
formApi.state.submissionAttempts > 0 ? yourValidator : undefined,
onSubmit: ({ formApi }) => formApi.state.submissionAttempts == 0 ? yourValidator : undefined
},
}); |
Beta Was this translation helpful? Give feedback.
-
React Hook Form by default does not append errors form the form level schema unless the user actually touches the field. This makes it so users can't really control when the error is appended (They abstract that away). TSF differs in that we ALWAYS append the errors to the corresponding errorMap/errors array for each field. You then have full control of when to display the error by using field.isTouched or similar to what Balastrong suggested using form.state.submissionAttempts. |
Beta Was this translation helpful? Give feedback.
-
I'm also interested in a better way to achieve this with Tanstack Form. The current workaround isn't really developer friendly as you have to repeat your validator twice, and repeat it every time you use |
Beta Was this translation helpful? Give feedback.
-
Hi guys, I would like to know how to replicate the defaults from react-hook-form in tanstack-form.
In the docs I only found one example with validation defined in onChange that runs on form level. Unfortunately it runs all validators immediately after user starts typing which to me is not the best user experience https://tanstack.com/form/latest/docs/framework/react/examples/large-form
What I would like to achieve is to define one zod schema, that will validate the form but only after form is initially submitted => then I would like to validate as user types so basically this is default from react-hook-form
example https://codesandbox.io/p/devbox/react-hook-form-with-zod-forked-vg3n4y?file=%2Fsrc%2FApp.js%3A37%2C32
Is it easy to achieve in @tanstack/react-form or rather requires a lot of effort? I would be grateful for any basic example that can replicate it. Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions