Skip to content

fix(form-core): re-run form-level validator on resubmit to clear its own stale field errors - #2260

Draft
FrancoKaddour wants to merge 1 commit into
TanStack:mainfrom
FrancoKaddour:fix/form-level-validator-resubmit
Draft

fix(form-core): re-run form-level validator on resubmit to clear its own stale field errors#2260
FrancoKaddour wants to merge 1 commit into
TanStack:mainfrom
FrancoKaddour:fix/form-level-validator-resubmit

Conversation

@FrancoKaddour

Copy link
Copy Markdown

Closes #2248

Problem

With only a form-level onSubmit validator (no field-level validators), the form can never re-validate on a second submit while any error is outstanding.

_handleSubmit runs validateAllFields('submit') (field-level only), then bails at if (!this.state.isFieldsValid) return — before this.validate('submit') (the form-level validator) is reached. A form-level validator writes its errors onto fields ({ fields }), but validateAllFields can't clear or recompute them, so isFieldsValid stays false from the previous submit and the form-level validator never re-runs — gating the form off permanently (even with canSubmitWhenInvalid: true).

Fix

Run the form-level validator right after validateAllFields, guarded by whether any field-level validator errored this submit (validateAllFields returns 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-core unit test reproducing #2248 (form-level-only validator, fill fields, resubmit → errors clear and onSubmit runs). Full form-core (504) and react-form (126) suites pass; the existing field-validator-gating test still passes.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 10bb5888-fe93-4055-a63f-c2039b07fa92

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

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.

Form-level validator doesn't re-run after first submit while fields hold errors — bug or by design?

1 participant