fix(form-core): keep onSubmit error when blurring an unchanged field#2211
fix(form-core): keep onSubmit error when blurring an unchanged field#2211chatman-media wants to merge 1 commit into
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesonSubmit error lifecycle fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. Comment |
Closes #1242
Problem
A field-level
onSubmiterror 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 storedsubmiterror fired for any cause other than'submit':handleBlurruns validation withcause: 'blur', which satisfiedcause !== 'submit', so a plain blur (no edit) cleared the submit error.Fix
Clear the stored submit error only on an actual value
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 onmain, passes with the fixshould clear onSubmit errors once a valid value is entered— guards the documented clear-on-change pathFull
form-coresuite green (107 tests).Summary by CodeRabbit
Bug Fixes
Tests