Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): clear stale onBlur errors on re-submission #2120

MergedrestareaByWeezy(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2120/headmerged by crutchcorn(GitHub profile, opens in a new tab)

Showing 3 changed files with 65 additions and 6 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fix-stale-onblur-resubmit.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+fix(form-core): clear stale onBlur errors on re-submission
13 additions and 6 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -2437,12 +2437,19 @@
submitMeta ?? (this.options.onSubmitMeta as TSubmitMeta)
if (!this.state.canSubmit && !this._devtoolsSubmissionOverride) {
- this.options.onSubmitInvalid?.({
- value: this.state.values,
- formApi: this,
- meta: submitMetaArg,
- })
- return
+ // On re-submission (submissionAttempts > 1), skip the early return so
+ // validateAllFields can re-run and clear stale field errors (e.g. from a
+ // previous onBlur validation that is no longer relevant). The
+ // isFieldsValid check below will call onSubmitInvalid if the form is
+ // still invalid after re-validation.
+ if (this.baseStore.state.submissionAttempts <= 1) {
+ this.options.onSubmitInvalid?.({