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

Field submit error is removed on field blur without a change #1242

Open
matthiasschwarz opened this issue Mar 7, 2025 · 1 comment
Open

Comments

@matthiasschwarz
Copy link

Describe the bug

A submit error is removed on blur of a field when the value didn't change.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/hungry-sanderson-ycs6rd

Steps to reproduce

  1. Press submit without entering a name
  2. Focus the name input field
  3. Leave focus without a change

Expected behavior

The error which occured on submit is not removed on blur when the value during focus didn't change.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: WIndows
  • Browser: Chrome

TanStack Form adapter

react-form

TanStack Form version

1.0.2

TypeScript version

No response

Additional context

No response

@theVedanta
Copy link
Contributor

theVedanta commented Mar 8, 2025

From what I find, the onChange validator will rightly handle the blurring by maintaining errors in the state.meta.errors. onSubmit however, is causing the blur event to clear the errors.

I might be wrong but I think this is where the problem is inFieldApi.ts:

/**
 *  when we have an error for onSubmit in the state, we want
 *  to clear the error as soon as the user enters a valid value in the field
 */
const submitErrKey = getErrorMapKey('submit')

if (
  this.state.meta.errorMap[submitErrKey] &&
  cause !== 'submit' &&
  !hasErrored
) {
  this.setMeta((prev) => ({
    ...prev,
    errorMap: {
      ...prev.errorMap,
      [submitErrKey]: undefined,
    },
  }))
}

Since blur's cause is not submit, but rather "change" in the case where we blur out of a field after submitting, it won't remap the hasErrored or the errorMap. I don't know if this is by design so I will let a maintainer comment on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants