Skip to content

fix(form-core): keep onSubmit error when blurring an unchanged field#2211

Open
chatman-media wants to merge 1 commit into
TanStack:mainfrom
chatman-media:fix/submit-error-cleared-on-blur
Open

fix(form-core): keep onSubmit error when blurring an unchanged field#2211
chatman-media wants to merge 1 commit into
TanStack:mainfrom
chatman-media:fix/submit-error-cleared-on-blur

Conversation

@chatman-media

@chatman-media chatman-media commented Jun 14, 2026

Copy link
Copy Markdown

Closes #1242

Problem

A field-level onSubmit error is wrongly cleared when the user focuses and blurs the field without changing its value. The submit error should only disappear once the user actually enters a (valid) value.

Root cause

In FieldApi, the logic that clears a stored submit error fired for any cause other than 'submit':

this.state.meta.errorMap?.[submitErrKey] &&
cause !== 'submit' &&
!hasErrored

handleBlur runs validation with cause: 'blur', which satisfied cause !== 'submit', so a plain blur (no edit) cleared the submit error.

Fix

Clear the stored submit error only on an actual value change:

cause === 'change' &&

A blur (or any non-value cause) no longer drops the submit error. Entering a valid value still clears it as documented.

Tests

Two tests added to packages/form-core/tests/FieldApi.spec.ts:

  • should not clear onSubmit errors on blur when the value did not changefails on main, passes with the fix
  • should clear onSubmit errors once a valid value is entered — guards the documented clear-on-change path

Full form-core suite green (107 tests).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed form validation to properly preserve submit errors during blur and non-value interactions. Submit errors are now cleared only when valid values are entered, improving form error feedback accuracy.
  • Tests

    • Extended test coverage for submit error behavior, verifying errors persist on blur without changes and clear when valid values are entered.

The submit-error auto-clear in FieldApi.validateSync fired on every
non-submit validation cause, including blur. As a result, focusing and
leaving a field without editing it dropped a valid submit error.

Gate the clear on a value `change` cause so the error is only removed
when the user actually enters a new value, matching the documented
intent of the block.

Closes TanStack#1242
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5e7097f8-a41c-492e-b209-cf17699f7708

📥 Commits

Reviewing files that changed from the base of the PR and between 6a73479 and 1d7dbe6.

📒 Files selected for processing (2)
  • packages/form-core/src/FieldApi.ts
  • packages/form-core/tests/FieldApi.spec.ts

📝 Walkthrough

Walkthrough

FieldApi.validateSync is updated to clear the stored onSubmit error only when cause === 'change', instead of when cause !== 'submit'. Two tests are added: one confirming the error persists after a post-submit blur, and one confirming it clears after a valid handleChange.

Changes

onSubmit error lifecycle fix

Layer / File(s) Summary
validateSync condition and tests
packages/form-core/src/FieldApi.ts, packages/form-core/tests/FieldApi.spec.ts
The clearing condition is narrowed to cause === 'change' with an updated comment; two new async tests verify that onSubmit errors survive a blur and are removed only when a valid value is entered via handleChange.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Hop, hop — the blur once wiped my error away,
But now I guard submit mistakes come what may!
A change of heart? I'll clear the slate with glee.
A sneaky blur? The error stays, you see.
No more silent vanishing acts from me! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: keeping onSubmit errors when blurring unchanged fields.
Description check ✅ Passed The PR description comprehensively covers the problem, root cause, fix, and testing, meeting the template's core requirements.
Linked Issues check ✅ Passed The PR fully addresses issue #1242 by fixing the bug where submit errors are incorrectly cleared on blur without value changes.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the submit error clearing behavior in FieldApi and adding related test coverage; no unrelated modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Successfully merging this pull request may close these issues.

Field submit error is removed on field blur without a change

1 participant