diff --git a/packages/core/src/__tests__/field.spec.ts b/packages/core/src/__tests__/field.spec.ts index c50bd7adf92..f3a6191c997 100644 --- a/packages/core/src/__tests__/field.spec.ts +++ b/packages/core/src/__tests__/field.spec.ts @@ -2207,3 +2207,17 @@ test('conflict name for errors filter', async () => { await aa1.onInput('') expect(aa.invalid).toBe(false) }) + +test('field destroyed can not be assign value', () => { + const form = attach(createForm()) + const aa = attach( + form.createField({ + name: 'aa', + }) + ) + aa.destroy() + aa.initialValue = 222 + aa.value = 111 + expect(form.values).toEqual({}) + expect(form.initialValues).toEqual({}) +}) diff --git a/packages/core/src/models/Field.ts b/packages/core/src/models/Field.ts index cd926af671b..fbfbaf6dbd5 100644 --- a/packages/core/src/models/Field.ts +++ b/packages/core/src/models/Field.ts @@ -351,6 +351,7 @@ export class Field< } set value(value: ValueType) { + if (this.destroyed) return if (!this.initialized) { if (this.display === 'none') { this.caches.value = value @@ -364,6 +365,7 @@ export class Field< } set initialValue(initialValue: ValueType) { + if (this.destroyed) return if (!this.initialized) { if ( !allowAssignDefaultValue(this.initialValue, initialValue) &&