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

Array fields do not run onChange validation #662

Open
gutentag2012 opened this issue Mar 30, 2024 · 2 comments · May be fixed by #700
Open

Array fields do not run onChange validation #662

gutentag2012 opened this issue Mar 30, 2024 · 2 comments · May be fixed by #700
Labels
bug good first issue Good for newcomers

Comments

@gutentag2012
Copy link

Describe the bug

When calling the array helper method pushValue or removeValue, no onChange validation is triggered on the array field that called the helper methods.

The validation is only run, when setting the isTouched state manually and calling the field.validate("change") method manually.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-8sihxk?file=src%2Findex.tsx

Steps to reproduce

  1. Click the button "Add one"
  2. Notice, there is no error
  3. Click the button "Validate"
  4. Now there is an error
  5. Click the button "Add one" one more time
  6. The error is still there
  7. Click the button "Validate" again
  8. The error is now gone

Expected behavior

As a user, I would expect every method that results in a mutation to validate for the "change" event, but that does not happen for the array helper methods.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome
  • Version: 0.19.0

TanStack Form adapter

react-form

TanStack Form version

v0.19.0

TypeScript version

v5.4.3

Additional context

This is not part of this bug, but I would also think working with the array helper methods would be easier if they would also allow for setting the touched state when using the FieldApi.

@dawsonbooth
Copy link

dawsonbooth commented Apr 4, 2024

I was running into a similar issue that's related to this; updating one field that is nested under array did not update the array state. But, after adding an onChangeListenTo validator on a neighboring field, the array state started updating.

Never mind, this is exactly what form.Subscribe is for 😅

@gutentag2012
Copy link
Author

@crutchcorn I created a PR that should fix this issue, if you want to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants