Skip to content
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

validateAllFields isn't working with touched fields #521

Closed
Hatzl opened this issue Nov 13, 2023 · 5 comments · Fixed by #526
Closed

validateAllFields isn't working with touched fields #521

Hatzl opened this issue Nov 13, 2023 · 5 comments · Fixed by #526

Comments

@Hatzl
Copy link

Hatzl commented Nov 13, 2023

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

  1. click on validate -> errors will be shown
  2. 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

@Hatzl
Copy link
Author

Hatzl commented Nov 13, 2023

I see the reason is HERE only "untouched" fields are validated.

Is this behaviour intended? How can I also validate touched fields?

@fallenleavesguy
Copy link

I want to validate all fields at once when people clicked a button too

@chaozwn
Copy link

chaozwn commented Dec 1, 2023

i need to manual validate fields at submit.

@crutchcorn
Copy link
Member

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.

@crutchcorn
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants