Skip to content
Source
Sign inSign up
TanStack/form

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 intomain fromrefs/pull/2260/headopened

Showing 3 changed files with 53 additions and 3 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/form-level-validator-resubmit.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/form-core": patch
+---
+​
+Re-run a form-level `onSubmit` validator on every submit (when no field-level validator errored) so it can recompute and clear its own field errors. Previously a form configured with only a form-level validator could be permanently gated by stale errors, because `_handleSubmit` bailed on `isFieldsValid` before the form-level validator re-ran (#2248).
11 additions and 3 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -2465,8 +2465,18 @@
this.baseStore.setState((prev) => ({ ...prev, isSubmitting: false }))
- await this.validateAllFields('submit')
+ const fieldErrors = await this.validateAllFields('submit')
+ // A form-level validator owns its field errors (via `{ fields }`), so it must
+ // re-run on every submit to recompute/clear them; otherwise stale errors from
+ // a prior submit keep `isFieldsValid` false and gate the form off permanently
+ // when there are no field-level validators to clear them (#2248). Only run it
+ // here when no field-level validator errored this submit — if the fields are
+ // already invalid on their own, the form validator is skipped as before.
+ if (fieldErrors.length === 0) {
+ await this.validate('submit')
+ }
+​