From fc269f528c0ae5bb62d640d27a2c3cd6acb61c49 Mon Sep 17 00:00:00 2001 From: Pejman Nikram Date: Sun, 28 Sep 2025 09:18:21 +0300 Subject: [PATCH 1/3] fix(form-core): respect dontValidate option in formApi array modifiers check the `dontValidate` option in array modifiers before applying validation fix #1764 --- .changeset/fresh-bikes-clap.md | 5 +++ packages/form-core/src/FormApi.ts | 64 ++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 .changeset/fresh-bikes-clap.md diff --git a/.changeset/fresh-bikes-clap.md b/.changeset/fresh-bikes-clap.md new file mode 100644 index 000000000..e1d4747a6 --- /dev/null +++ b/.changeset/fresh-bikes-clap.md @@ -0,0 +1,5 @@ +--- +'@tanstack/form-core': minor +--- + +respect dontValidate option in formApi array modifiers diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index 6afa0fdc9..8dd44c29f 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -2301,13 +2301,18 @@ export class FormApi< mergeOpts(options, { dontValidate: true }), ) - // Validate the whole array + all fields that have shifted - await this.validateField(field, 'change') - + const dontValidate = options?.dontValidate ?? false + if (!dontValidate) { + // Validate the whole array + all fields that have shifted + await this.validateField(field, 'change') + } + // Shift down all meta after validating to make sure the new field has been mounted metaHelper(this).handleArrayFieldMetaShift(field, index, 'insert') - await this.validateArrayFieldsStartingFrom(field, index, 'change') + if (!dontValidate) { + await this.validateArrayFieldsStartingFrom(field, index, 'change') + } } /** @@ -2331,9 +2336,12 @@ export class FormApi< mergeOpts(options, { dontValidate: true }), ) - // Validate the whole array + all fields that have shifted - await this.validateField(field, 'change') - await this.validateArrayFieldsStartingFrom(field, index, 'change') + const dontValidate = options?.dontValidate ?? false + if (!dontValidate) { + // Validate the whole array + all fields that have shifted + await this.validateField(field, 'change') + await this.validateArrayFieldsStartingFrom(field, index, 'change') + } } /** @@ -2368,9 +2376,12 @@ export class FormApi< this.deleteField(start as never) } - // Validate the whole array + all fields that have shifted - await this.validateField(field, 'change') - await this.validateArrayFieldsStartingFrom(field, index, 'change') + const dontValidate = options?.dontValidate ?? false + if (!dontValidate) { + // Validate the whole array + all fields that have shifted + await this.validateField(field, 'change') + await this.validateArrayFieldsStartingFrom(field, index, 'change') + } } /** @@ -2395,11 +2406,14 @@ export class FormApi< // Swap meta metaHelper(this).handleArrayFieldMetaShift(field, index1, 'swap', index2) - // Validate the whole array - this.validateField(field, 'change') - // Validate the swapped fields - this.validateField(`${field}[${index1}]` as DeepKeys, 'change') - this.validateField(`${field}[${index2}]` as DeepKeys, 'change') + const dontValidate = options?.dontValidate ?? false + if (!dontValidate) { + // Validate the whole array + this.validateField(field, 'change') + // Validate the swapped fields + this.validateField(`${field}[${index1}]` as DeepKeys, 'change') + this.validateField(`${field}[${index2}]` as DeepKeys, 'change') + } } /** @@ -2424,11 +2438,14 @@ export class FormApi< // Move meta between index1 and index2 metaHelper(this).handleArrayFieldMetaShift(field, index1, 'move', index2) - // Validate the whole array - this.validateField(field, 'change') - // Validate the moved fields - this.validateField(`${field}[${index1}]` as DeepKeys, 'change') - this.validateField(`${field}[${index2}]` as DeepKeys, 'change') + const dontValidate = options?.dontValidate ?? false + if (!dontValidate) { + // Validate the whole array + this.validateField(field, 'change') + // Validate the moved fields + this.validateField(`${field}[${index1}]` as DeepKeys, 'change') + this.validateField(`${field}[${index2}]` as DeepKeys, 'change') + } } /** @@ -2457,8 +2474,11 @@ export class FormApi< } } - // validate array change - this.validateField(field, 'change') + const dontValidate = options?.dontValidate ?? false + if (!dontValidate) { + // validate array change + this.validateField(field, 'change') + } } /** From 3e3ab5e4b5122474d968c1b33b2d8d536201913c Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 08:27:34 +0000 Subject: [PATCH 2/3] ci: apply automated fixes and generate docs --- packages/form-core/src/FormApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index 8dd44c29f..88d5ac9c5 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -2306,7 +2306,7 @@ export class FormApi< // Validate the whole array + all fields that have shifted await this.validateField(field, 'change') } - + // Shift down all meta after validating to make sure the new field has been mounted metaHelper(this).handleArrayFieldMetaShift(field, index, 'insert') From be6add45a65ce95f8427d1a577e253374bb2fe00 Mon Sep 17 00:00:00 2001 From: Pejman Nikram Date: Sun, 28 Sep 2025 14:42:53 +0300 Subject: [PATCH 3/3] fix(form-core): change changeset to patch --- .changeset/fresh-bikes-clap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fresh-bikes-clap.md b/.changeset/fresh-bikes-clap.md index e1d4747a6..125c722ee 100644 --- a/.changeset/fresh-bikes-clap.md +++ b/.changeset/fresh-bikes-clap.md @@ -1,5 +1,5 @@ --- -'@tanstack/form-core': minor +'@tanstack/form-core': patch --- respect dontValidate option in formApi array modifiers