From db349ccb68ce680c208b8f91c97cc29367d7bda3 Mon Sep 17 00:00:00 2001 From: black Date: Mon, 22 May 2023 17:22:01 +0800 Subject: [PATCH] fix: can't set default value when turn on the form field required (#1887) * fix: can't set default value when turn on the form field required * fix: can't set default value when turn on the association select field required --- .../antd/association-select/AssociationSelect.tsx | 8 +++++--- .../src/schema-component/antd/form-item/FormItem.tsx | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx index 2831e50e0..85e117e35 100644 --- a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx @@ -160,6 +160,8 @@ AssociationSelect.Designer = function Designer() { readOnlyMode = 'read-pretty'; } + const fieldSchemaWithoutRequired = _.omit(fieldSchema,'required') + return ( @@ -299,10 +301,10 @@ AssociationSelect.Designer = function Designer() { title: t('Set default value'), properties: { default: { - ...(fieldSchema || {}), + ...(fieldSchemaWithoutRequired || {}), 'x-decorator': 'FormItem', 'x-component-props': { - ...fieldSchema['x-component-props'], + ...fieldSchemaWithoutRequired['x-component-props'], component: collectionField?.target ? 'AssociationSelect' : undefined, service: { resource: collectionField?.target, @@ -812,7 +814,7 @@ AssociationSelect.FilterDesigner = function FilterDesigner() { title: t('Set default value'), properties: { default: { - ...collectionField?.uiSchema, + ..._.omit(collectionField?.uiSchema, 'required'), name: 'default', title: t('Default value'), 'x-decorator': 'FormItem', diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index 46f3988da..a633a85af 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -172,6 +172,8 @@ FormItem.Designer = function Designer() { }; }); + const fieldSchemaWithoutRequired = _.omit(fieldSchema,'required') + return ( @@ -352,7 +354,7 @@ FormItem.Designer = function Designer() { properties: { default: isInvariable(interfaceConfig) ? { - ...(fieldSchema || {}), + ...(fieldSchemaWithoutRequired || {}), 'x-decorator': 'FormItem', 'x-component-props': { ...fieldSchema['x-component-props'], @@ -375,7 +377,7 @@ FormItem.Designer = function Designer() { 'x-disabled': false, } : { - ...(fieldSchema || {}), + ...(fieldSchemaWithoutRequired || {}), 'x-decorator': 'FormItem', 'x-component': 'VariableInput', 'x-component-props': { @@ -384,7 +386,7 @@ FormItem.Designer = function Designer() { schema: collectionField?.uiSchema, className: defaultInputStyle, renderSchemaComponent: function Com(props) { - const s = _.cloneDeep(fieldSchema) || ({} as Schema); + const s = _.cloneDeep(fieldSchemaWithoutRequired) || ({} as Schema); s.title = ''; s['x-read-pretty'] = false; s['x-disabled'] = false;