Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): prevent removeValue from auto-touching shifted siblings #2133

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

Showing 1 changed file with 31 additions and 2 deletions.

x
0 of 1 viewed, 1 left
31 additions and 2 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -1582,6 +1582,7 @@
field: TField,
index: number,
cause: ValidationCause,
+ options?: { avoidTouch?: boolean },
) => {
const currentValue = this.getFieldValue(field)
@@ -1605,7 +1606,32 @@
batch(() => {
fieldsToValidate.forEach((nestedField) => {
fieldValidationPromises.push(
- Promise.resolve().then(() => this.validateField(nestedField, cause)),
+ Promise.resolve().then(async () => {
+ // If avoidTouch is set and the field instance already exists,
+ // run validation without permanently marking the field as touched
+ if (options?.avoidTouch) {
+ const fieldInstance = this.fieldInfo[nestedField]?.instance
+ if (fieldInstance) {
+ const wasTouched = fieldInstance.state.meta.isTouched
+ if (!wasTouched) {
+ // Temporarily touch the field so validation runs, then restore
+ fieldInstance.setMeta((prev) => ({
+ ...prev,
+ isTouched: true,