Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): keep onSubmit error when blurring an unchanged field #2211

Openchatman-media(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2211/headopened

Showing 2 changed files with 63 additions and 2 deletions.

x
0 of 2 viewed, 2 left
5 additions and 2 deletionspackages/form-core/src/FieldApi.tsModified
View file
@@ -1347,14 +1347,17 @@
* when we have an error for onSubmit in the state, we want
- * to clear the error as soon as the user enters a valid value in the field
+ * to clear the error as soon as the user enters a valid value in the field.
+ * This must only happen on a value `change` - clearing it on `blur` (or any
+ * other non-value cause) would wrongly drop the submit error when the user
+ * focuses and leaves the field without editing it.
const submitErrKey = getErrorMapKey('submit')
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
this.state.meta.errorMap?.[submitErrKey] &&
- cause !== 'submit' &&
+ cause === 'change' &&
!hasErrored
this.setMeta((prev) => ({
58 additions and 0 deletionspackages/form-core/tests/FieldApi.spec.tsModified
View file
@@ -2098,6 +2098,64 @@