fix(form-core): re-run form-level validator on resubmit to clear its own stale field errors #2260
OpenFrancoKaddour(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/2260/headopened - @@ -1946,0 +1957,21 @@1957+ },1958+ },1959+ canSubmitWhenInvalid: true,1960+ onSubmit,1961+ })1962+ form.mount()1963+1964+ // 1) Submit empty -> the form-level validator flags both fields.1965+ await form.handleSubmit()1966+ expect(form.state.fieldMeta.name?.errorMap.onSubmit).toBe('Required')1967+ expect(form.state.fieldMeta.other?.errorMap.onSubmit).toBe('Required')1968+ expect(onSubmit).not.toHaveBeenCalled()1969+1970+ // 2) Fill both fields so the form-level validator would now pass.1971+ form.setFieldValue('name', 'John')1972+ form.setFieldValue('other', 'thing')1973+1974+ // 3) Submit again -> the form-level validator must re-run, clear the stale1975+ // errors, and the form should submit. Currently `_handleSubmit` bails on1976+ // the stale `isFieldsValid === false` before `validate('submit')` re-runs,1977+ // so the errors never clear and the form can never be submitted.
FrancoKaddour(GitHub profile, opens in a new tab) linked this to fix #2248
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
4fb62140-46e5-4d3e-aabc-76e0f15f915c📥 Commits
Reviewing files that changed from the base of the PR and between 7840e02759d8a704080bf4e1d6b8e0494bcf4f4b and 95847a7d2c17325194ac71e039865d3457479f01.
📒 Files selected for processing (1)
packages/form-core/tests/FormApi.spec.ts🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
Walkthrough#
Form submission now reruns form-level validation when field validation has no errors. A regression test verifies that corrected values clear stale errors and allow
onSubmitto run. A patch changeset documents the behavior.Changes#
Form validation resubmission
packages/form-core/src/FormApi.tspackages/form-core/tests/FormApi.spec.ts,.changeset/form-level-validator-resubmit.mdonSubmit. The changeset documents the patch release.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.
❤️ Share