Skip to content
Source
Sign inSign up
TanStack/form

onBlur validation weird behaviour #1587

Send to my agent
Closedkimsagro1(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

onBlur validation is showing a validation message for a required field when the field is not blank

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-jxykqf4t?file=src%2Findex.tsx&preset=node

Steps to reproduce

  1. Click into the first name input
  2. Tab into the last name input
  3. Start typing into the last name input
  4. The "lastname required" message is display

Expected behavior

I would not expected the "lastname required" message to be displayed when the field is not empty.

How often does this bug happen?

Every time

Screenshots or Videos

https://github.com/user-attachments/assets/189d939f-1d0c-47c1-a11f-04cabe827816

Platform

Windows, Chrome 137

TanStack Form adapter

react-form

TanStack Form version

1.12.3

TypeScript version

5.8.3

Additional context

No response

  1. What's happening is the combination of form-level validation and the onBlur event.

    Here's a description of your "steps to reproduce":

    1. Click into the first name input No validation has triggered yet
    2. Tab into the last name input First name is blurred, so TSF runs the onBlur validation event.
    • First Name has no onBlur validator, so it's skipped
    • Form onBlur validator is run. It creates errors for First Name and Last Name
    • Errors are configured to not show then touched (see line 10). First Name is touched so it will show the error. Last Name is not touched so it won't show the error. 3. Start typing into the last name input
    • Changing a field marks the field as touched. Last Name is now touched.
    • It reveals the error generated from step 2. 4. The "lastname required" message is display

    To summarize, this is intended behaviour. The fix depends on what you actually want the behaviour to be, as onBlur validation only runs on blur.

Sign in to join this conversation.