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 change — fails 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.
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 6a73479f2c2659550a6c8b456e3e139bf0d2142e and 1d7dbe6aea9e0d9e4e1b81e1d6d56a6bb58752af.
📒 Files selected for processing (2)
packages/form-core/src/FieldApi.tspackages/form-core/tests/FieldApi.spec.ts📝 Walkthrough
Walkthrough#
FieldApi.validateSyncis updated to clear the storedonSubmiterror only whencause === 'change', instead of whencause !== 'submit'. Two tests are added: one confirming the error persists after a post-submit blur, and one confirming it clears after a validhandleChange.Changes#
onSubmit error lifecycle fix
validateSynccondition and testspackages/form-core/src/FieldApi.ts,packages/form-core/tests/FieldApi.spec.tscause === 'change'with an updated comment; two new async tests verify thatonSubmiterrors survive a blur and are removed only when a valid value is entered viahandleChange.Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~8 minutes
Poem#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#1242by fixing the bug where submit errors are incorrectly cleared on blur without value changes.✨ Finishing Touches
🧪 Generate unit tests (beta)
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