Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): mark unrendered fields as touched on submit #2449

Openokxint(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/2449/headopened

Showing 2 changed files with 41 additions and 7 deletions.

x
0 of 2 viewed, 2 left
5 additions and 0 deletions.changeset/fix-unrendered-fields-touched-on-submit.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+Mark unrendered fields as touched when the form is submitted
36 additions and 7 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -2428,16 +2428,45 @@
batch(() => {
- void (Object.values(this.fieldInfo) as FieldInfo<any>[]).forEach(
- (field) => {
- if (!field.instance) return
- // If any fields are not touched
+ const untouchedUnrendered: Array<DeepKeys<TFormData>> = []
+​
+ void (
+ Object.entries(this.fieldInfo) as [
+ DeepKeys<TFormData>,
+ FieldInfo<any>,
+ ][]
+ ).forEach(([fieldName, field]) => {
+ if (field.instance) {
+ // Rendered field: update through the live instance
if (!field.instance.store.state.meta.isTouched) {
- // Mark them as touched
field.instance.setMeta((prev) => ({ ...prev, isTouched: true }))