diff --git a/packages/core/src/__tests__/form.spec.ts b/packages/core/src/__tests__/form.spec.ts index 02ba972e891..fc89ec7fa1a 100644 --- a/packages/core/src/__tests__/form.spec.ts +++ b/packages/core/src/__tests__/form.spec.ts @@ -1123,6 +1123,7 @@ test('setValues deep merge', () => { aa: { bb: 123, cc: 321, + dd: [11, 22, 33], }, }, }) @@ -1131,18 +1132,21 @@ test('setValues deep merge', () => { aa: { bb: 123, cc: 321, + dd: [11, 22, 33], }, }) form.setValues({ aa: { bb: '', cc: '', + dd: [44, 55, 66], }, }) expect(form.values).toEqual({ aa: { bb: '', cc: '', + dd: [44, 55, 66], }, }) }) diff --git a/packages/core/src/models/Form.ts b/packages/core/src/models/Form.ts index e47616e3fea..d3e3abed8d1 100644 --- a/packages/core/src/models/Form.ts +++ b/packages/core/src/models/Form.ts @@ -399,7 +399,9 @@ export class Form { if (!isPlainObj(values)) return untracked(() => { if (strategy === 'merge' || strategy === 'deepMerge') { - this.values = merge(this.values, values) + this.values = merge(this.values, values, { + arrayMerge: (target, source) => source, + }) } else if (strategy === 'shallowMerge') { this.values = Object.assign(this.values, values) } else { @@ -415,7 +417,9 @@ export class Form { if (!isPlainObj(initialValues)) return untracked(() => { if (strategy === 'merge' || strategy === 'deepMerge') { - this.initialValues = merge(this.initialValues, initialValues) + this.initialValues = merge(this.initialValues, initialValues, { + arrayMerge: (target, source) => source, + }) } else if (strategy === 'shallowMerge') { this.initialValues = Object.assign(this.initialValues, initialValues) } else {