validateAllFields isn't working with touched fields
Hatzl opened this issue · comments
Describe the bug
If you call form.validateAllFields("change")
and have initial form errors (e.g. empty required field) it returns the error.
If you call it again, it only returns a empty array. Also it isn't showing errors from touched fields.
Is this behaviour intended? How can I also validate touched fields?
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/keen-visvesvaraya-qnn26j?file=%2Fsrc%2Findex.tsx%3A41%2C62
Steps to reproduce
- click on validate -> errors will be shown
- click on validate again -> errors is empty
Expected behavior
form.validateAllFields("change")
should always return errors
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: MacOS
- Browser: Chrome
Tanstack Form adapter
react-form
TanStack Form version
0.9.0
TypeScript version
No response
Additional context
No response
I see the reason is HERE only "untouched" fields are validated.
Is this behaviour intended? How can I also validate touched fields?
I want to validate all fields at once when people clicked a button too
i need to manual validate fields at submit.
Hey y'all - I'm investigating this now.
However @fallenleavesguy @chaozwn, I will note that I think y'all aren't facing the same issue as @Hatzl. Instead, take a look at the newly released 0.10.x
releases, which introduce the ability to validate all fields in change
and blur
during a submit.
I've just opened #526 to solve this issue.
This actually got me thinking about how we're doing (and exposing) validation. The return types are kinda all over the place and we should probably restrict some of these methods to _
to make it clear that they're intended for internals only.
0.10.3
carries this fix but be aware that we're likely to make substantial changes to the API of validateAllFields
and similar semi-internal methods before v1.