Skip to content
Source
Sign inSign up
TanStack/form

Field-level validation does not run on submit. #2034

Send to my agent
Closedaihdene-genetec(GitHub profile, opens in a new tab) opened this issue 8 comments

Describe the bug

Field-level validation does not run on submit.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/tanstack-bug-forked-sxjrg6

Steps to reproduce

  1. Set select to PIN
  2. Press Submit
  3. Notice how REQUIRED error shows up
  4. Change select to Card
  5. Press Submit
  6. Notice how REQUIRED is still there and the form cannot be submitted

Expected behavior

As a user, I expected the form to be able to be submitted when I press Submit for the second time since the field state should be valid on the second submit.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Browser: Chrome
  • OS: MacOS
  • Browser Version: 145.0.7632.45

TanStack Form adapter

react-form

TanStack Form version

v1.28.0

TypeScript version

v4.4.4

Additional context

No response

  1. This mitigates the issue for me:

          <button
            onClick={async () => {
              await form.validateAllFields("submit");
              form.handleSubmit();
            }}
          >
            Submit
          </button>

    But I don't expect to call validateAllFields myself. I expect the form to revalidate all fields when you submit.

  2. Hi there! I have a very similar issue with handleSubmit not being called. I tracked back the version that last worked for me which was 1.27.4. Upgrading to 1.27.5 onward (including latest 1.28.3 at this time), have this regression.

    Hopefully this helps

  3. This appears to be related to validators running on onBlur. If a field-level onBlur validator has run, and is invalid, that invalid onBlur validation will prevent all fields from validating when you submit

  4. Having a similar issue. First submit invalidates the field, and then it's impossible to resubmit until I blur.

  5. @restareaByWeezy do you wanna submit your PR officially?

  6. Opened a PR for this: #2120

    The root cause is that _handleSubmit bails out early when canSubmit is false — before validateAllFields gets a chance to re-run and clear stale onBlur errors. The fix skips that early return on re-submission so validators actually run again.

    One thing to note: the stale onBlur error in errorMap won't be visually cleared until the field is blurred again, since validateAllFields('submit') only touches the onSubmit key. The form does submit correctly though. If clearing the onBlur error on submit is desired, that'd be a separate change.

  7. I can confirm having this same issue in latest 1.33.0 version @crutchcorn It's been blocking my upgrade since version 1.27.5 (where the bug was introduced).

    Is it possible we get some eyes on this, please?

    Much appreciated for your time🙏

    Cheers

  8. Is this project still being maintained? This is a real bug & there is an open PR for a fix. @tannerlinsley

Sign in to join this conversation.