From 47ee47864c5a41f57899bf232f7c08b316263d39 Mon Sep 17 00:00:00 2001 From: Janry Date: Wed, 19 Oct 2022 20:37:06 +0800 Subject: [PATCH] fix(core): fix initial value is filtered when the field is hidden (#3471) --- packages/core/src/__tests__/field.spec.ts | 12 ++++++++++++ packages/core/src/models/Field.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/src/__tests__/field.spec.ts b/packages/core/src/__tests__/field.spec.ts index 4685ed13b25..a7f9b4d11c5 100644 --- a/packages/core/src/__tests__/field.spec.ts +++ b/packages/core/src/__tests__/field.spec.ts @@ -2295,3 +2295,15 @@ test('field actions', () => { }) expect(aa.invoke('test')).toEqual(321) }) + +test('field hidden value', () => { + const form = attach(createForm()) + attach( + form.createField({ + name: 'aa', + hidden: true, + initialValue: '123', + }) + ) + expect(form.values).toEqual({ aa: '123' }) +}) diff --git a/packages/core/src/models/Field.ts b/packages/core/src/models/Field.ts index 58d02dcab2c..8ee4020641a 100644 --- a/packages/core/src/models/Field.ts +++ b/packages/core/src/models/Field.ts @@ -228,7 +228,7 @@ export class Field< if (this.selfModified && !this.caches.inputting) { validateSelf(this) } - if (!this.visible) { + if (this.display === 'none') { this.caches.value = toJS(value) this.form.deleteValuesIn(this.path) }