Field-level validation does not run on submit. #2034
Send to my agentDescribe 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#
- Set select to PIN
- Press Submit
- Notice how REQUIRED error shows up
- Change select to Card
- Press Submit
- 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
aihdene-genetec(GitHub profile, opens in a new tab) changed the title
Hi there! I have a very similar issue with
handleSubmitnot 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
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
Having a similar issue. First submit invalidates the field, and then it's impossible to resubmit until I blur.
@restareaByWeezy do you wanna submit your PR officially?
Opened a PR for this: #2120
The root cause is that
_handleSubmitbails out early whencanSubmitis false — beforevalidateAllFieldsgets 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
onBlurerror inerrorMapwon't be visually cleared until the field is blurred again, sincevalidateAllFields('submit')only touches theonSubmitkey. The form does submit correctly though. If clearing the onBlur error on submit is desired, that'd be a separate change.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
Is this project still being maintained? This is a real bug & there is an open PR for a fix. @tannerlinsley
crutchcorn(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
This mitigates the issue for me:
But I don't expect to call validateAllFields myself. I expect the form to revalidate all fields when you submit.