fix(form-core): re-run form-level validator on resubmit to clear its own stale field errors - #2260
Conversation
…own stale field errors
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughForm submission now reruns form-level validation when field validation has no errors. A regression test verifies that corrected values clear stale errors and allow ChangesForm validation resubmission
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/form-core/tests/FormApi.spec.ts`:
- Around line 1974-1977: Update the regression comment in the FormApi test
around _handleSubmit to replace “Currently” with “Before this fix,” preserving
the description that the prior implementation bailed before validate('submit')
and documenting it as historical behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 451a049e-47dc-4dc9-a1d9-487de253cc4d
📒 Files selected for processing (3)
.changeset/form-level-validator-resubmit.mdpackages/form-core/src/FormApi.tspackages/form-core/tests/FormApi.spec.ts
Per review: the comment documented the bug in present tense, which reads as current behavior now that the fix is in place.
Closes #2248
Problem
With only a form-level
onSubmitvalidator (no field-level validators), the form can never re-validate on a second submit while any error is outstanding._handleSubmitrunsvalidateAllFields('submit')(field-level only), then bails atif (!this.state.isFieldsValid) return— beforethis.validate('submit')(the form-level validator) is reached. A form-level validator writes its errors onto fields ({ fields }), butvalidateAllFieldscan't clear or recompute them, soisFieldsValidstaysfalsefrom the previous submit and the form-level validator never re-runs — gating the form off permanently (even withcanSubmitWhenInvalid: true).Fix
Run the form-level validator right after
validateAllFields, guarded by whether any field-level validator errored this submit (validateAllFieldsreturns those errors). When none errored, it re-runs and recomputes/clears its own field errors; when field-level validators did error, it's skipped as before (preserving the existing "don't trigger form validators if field validators errored" behavior).Tests
Added a
form-coreunit test reproducing #2248 (form-level-only validator, fill fields, resubmit → errors clear andonSubmitruns). Fullform-core(504) andreact-form(126) suites pass; the existing field-validator-gating test still passes.Summary by CodeRabbit