From 683b63826ad5f5daf8b7f07403ae7ca04a2f6c7c Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 10 Mar 2022 13:53:42 +0800 Subject: [PATCH] fix(client): form item required --- .../antd/form-item/FormItem.tsx | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/client/src/schema-component/antd/form-item/FormItem.tsx index 04285abb8..2dc94ef02 100644 --- a/packages/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/client/src/schema-component/antd/form-item/FormItem.tsx @@ -2,6 +2,7 @@ import { FormItem as Item } from '@formily/antd'; import { Field } from '@formily/core'; import { ISchema, useField, useFieldSchema, useForm } from '@formily/react'; import React from 'react'; +import { useTranslation } from 'react-i18next'; import { useActionContext } from '..'; import { useCompile, useDesignable } from '../..'; import { useCollection, useCollectionManager } from '../../../collection-manager'; @@ -21,7 +22,8 @@ FormItem.Designer = () => { const { getField } = useCollection(); const field = useField(); const fieldSchema = useFieldSchema(); - const { dn, reset, refresh } = useDesignable(); + const { t } = useTranslation(); + const { dn, refresh } = useDesignable(); const compile = useCompile(); const collectionField = getField(fieldSchema['name']); const originalTitle = collectionField?.uiSchema?.title; @@ -60,12 +62,6 @@ FormItem.Designer = () => { 'x-component-props': {}, description: `原字段标题:${collectionField?.uiSchema?.title}`, }, - required: { - 'x-decorator': 'FormItem', - 'x-component': 'Checkbox', - 'x-content': '必填', - 'x-hidden': field.readPretty, - }, footer: { type: 'void', 'x-component': 'Action.Modal.Footer', @@ -96,7 +92,7 @@ FormItem.Designer = () => { const ctx = useActionContext(); return { async run() { - const { title, required, label } = form.values; + const { title } = form.values; const schema = { ['x-uid']: fieldSchema['x-uid'], @@ -108,10 +104,6 @@ FormItem.Designer = () => { schema['title'] = title; } - field.required = required; - fieldSchema['required'] = required; - schema['required'] = required; - ctx.setVisible(false); dn.emit('patch', { schema, @@ -129,6 +121,24 @@ FormItem.Designer = () => { } /> )} + {!field.readPretty && ( + { + const schema = { + ['x-uid']: fieldSchema['x-uid'], + }; + field.required = required; + fieldSchema['required'] = required; + schema['required'] = required; + dn.emit('patch', { + schema, + }); + refresh(); + }} + /> + )} {collectionField?.target && (