TanStack / TanStack/form

Inconsistent behavior between validators: onSubmit validates error fields on change, whereas onBlur always validates on blur

Open
#2,007 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

v1 v2: needs investigation
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

Describe the bug

After onBlur validation reveals an error, the onBlur validator will not run again until the field is blurred again. Whereas after onSubmit validation reveals an error, the onSubmit validator will re-run on change. The behavior of all the validators should be consistent. (Although it'd be more convenient for me personally if onBlur re-ran error fields on change but onSubmit re-ran them only on submit 😭)

Imo the correct behavior is to make them both revalidate error fields on change. This falls in line with the research-validated "reward early, punish late" pattern.

Your minimal, reproducible example

https://stackblitz.com/edit/github-vhbc3ekb?file=src%2Findex.tsx

Steps to reproduce
  1. Blur the first name field without entering any text. You will see an error message for the first name field.
  2. Enter text into the first name field. You will still see the error message.
  3. Blur the first name field. The error message will disappear
  4. Click the submit button. You will see an error message for the last name field.
  5. Enter text into the last name field. The error message will disappear
Expected behavior

I expected entering the text into the first name field to remove the error message without needing to be blurred first. The error message should disappear on change as soon as the field is valid the same way it works for on submit

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform
  • OS: Mac
  • Browser: Chrome v144.0.7559.97
TanStack Form adapter

react-form

TanStack Form version

v1.28.0

TypeScript version

v5.9.3

Additional context

Edit: I thought about it more and the existing onSubmit behavior can be recovered with onDynamic. That's a point in favor of changing onSubmit to work like onBlur instead of the other way around

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproduction in the linked StackBlitz at src/index.tsx and compare the onBlur and onSubmit validation flows described in the steps. Trace the relevant validator entry points in the form package, then verify that the chosen behavior consistently revalidates errored fields and that the reproduction no longer requires a second blur.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.