From 888dc47e5539c3086f62598424ea210a2a644b3f Mon Sep 17 00:00:00 2001 From: Janry Date: Wed, 30 Mar 2022 20:01:22 +0800 Subject: [PATCH] fix(antd/next): fix array string field addition logic (#2998) --- packages/antd/src/array-base/index.tsx | 12 ++++++------ packages/next/src/array-base/index.tsx | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/antd/src/array-base/index.tsx b/packages/antd/src/array-base/index.tsx index 8d5059467e7..5ad9af1fae5 100644 --- a/packages/antd/src/array-base/index.tsx +++ b/packages/antd/src/array-base/index.tsx @@ -85,13 +85,13 @@ const useRecord = (record?: number) => { const getSchemaDefaultValue = (schema: Schema) => { if (schema?.type === 'array') return [] - if (schema?.type === 'boolean') return true - if (schema?.type === 'date') return '' - if (schema?.type === 'datetime') return '' - if (schema?.type === 'number') return 0 if (schema?.type === 'object') return {} - if (schema?.type === 'string') return '' - return null + if (schema?.type === 'void') { + for (let key in schema.properties) { + const value = getSchemaDefaultValue(schema.properties[key]) + if (isValid(value)) return value + } + } } const getDefaultValue = (defaultValue: any, schema: Schema) => { diff --git a/packages/next/src/array-base/index.tsx b/packages/next/src/array-base/index.tsx index bb56f60bc21..87556a7a383 100644 --- a/packages/next/src/array-base/index.tsx +++ b/packages/next/src/array-base/index.tsx @@ -85,13 +85,13 @@ const useRecord = (record?: number) => { const getSchemaDefaultValue = (schema: Schema) => { if (schema?.type === 'array') return [] - if (schema?.type === 'boolean') return true - if (schema?.type === 'date') return '' - if (schema?.type === 'datetime') return '' - if (schema?.type === 'number') return 0 if (schema?.type === 'object') return {} - if (schema?.type === 'string') return '' - return null + if (schema?.type === 'void') { + for (let key in schema.properties) { + const value = getSchemaDefaultValue(schema.properties[key]) + if (isValid(value)) return value + } + } } const getDefaultValue = (defaultValue: any, schema: Schema) => {