From b7036a2930a07f3dc88ce96470632b8e2bb24351 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Wed, 14 Jul 2021 16:37:54 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=B8=8D=E8=87=AA=E5=8A=A8=E5=8C=85?= =?UTF-8?q?=E8=A3=B9=20asFormItem=20(#2275)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 不自动包裹 asFormItem * 改个名字 --- examples/components/Form/Custom.jsx | 3 +++ src/SchemaRenderer.tsx | 14 ++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/components/Form/Custom.jsx b/examples/components/Form/Custom.jsx index aa5b1b067..f58bbad2a 100644 --- a/examples/components/Form/Custom.jsx +++ b/examples/components/Form/Custom.jsx @@ -87,6 +87,7 @@ export default { { name: 'a', + asFormItem: true, children: ({value, onChange}) => (

这是使用 children 的方式,也无需注册。

@@ -129,6 +130,7 @@ export default { }, { label: '', + asFormItem: true, children: ({render}) => (

组合现有组件

@@ -158,6 +160,7 @@ export default { { name: 'c', label: '', + asFormItem: true, component: ({render, value, onChange, name}) => { function handleXChange(x) { value = { diff --git a/src/SchemaRenderer.tsx b/src/SchemaRenderer.tsx index ad7d1b69a..4d317bf25 100644 --- a/src/SchemaRenderer.tsx +++ b/src/SchemaRenderer.tsx @@ -121,12 +121,7 @@ export class SchemaRenderer extends React.Component { } else { // 自定义组件如果在节点设置了 label name 什么的,就用 formItem 包一层 // 至少自动支持了 valdiations, label, description 等逻辑。 - if ( - schema.children && - !schema.component && - (schema.asFormItem || - (props.formStore && (schema.name || schema.hasOwnProperty('label')))) - ) { + if (schema.children && !schema.component && schema.asFormItem) { schema.component = PlaceholderComponent; schema.renderChildren = schema.children; delete schema.children; @@ -134,9 +129,8 @@ export class SchemaRenderer extends React.Component { if ( schema.component && - !schema.component.wrapAsFormItem && - (schema.asFormItem || - (props.formStore && (schema.name || schema.hasOwnProperty('label')))) + !schema.component.wrapedAsFormItem && + schema.asFormItem ) { const cache = componentCache.get(schema.component); @@ -148,7 +142,7 @@ export class SchemaRenderer extends React.Component { ...schema.asFormItem })(schema.component); componentCache.set(schema.component, cache); - cache.wrapAsFormItem = true; + cache.wrapedAsFormItem = true; schema.component = cache; } }