Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): apply async defaultValues to untouched fields after other fields are edited #2246

Openxianjianlf2(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2246/headopened

Showing 3 changed files with 74 additions and 3 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/async-default-untouched-fields.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+fix(form-core): apply updated async `defaultValues` to untouched fields even after another field has been edited, instead of skipping the whole update once any field is touched (#2229)
21 additions and 3 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -1754,8 +1754,7 @@
const shouldUpdateValues =
options.defaultValues &&
- !evaluate(options.defaultValues, oldOptions.defaultValues) &&
- !this.state.isTouched
+ !evaluate(options.defaultValues, oldOptions.defaultValues)
const shouldUpdateState =
!evaluate(options.defaultState, oldOptions.defaultState) &&
@@ -1763,6 +1762,25 @@
if (!shouldUpdateValues && !shouldUpdateState) return
+ // Fields the user has already edited must keep their edited values, but