fix(client): form item required
This commit is contained in:
parent
fa16fe6fec
commit
683b63826a
@ -2,6 +2,7 @@ import { FormItem as Item } from '@formily/antd';
|
|||||||
import { Field } from '@formily/core';
|
import { Field } from '@formily/core';
|
||||||
import { ISchema, useField, useFieldSchema, useForm } from '@formily/react';
|
import { ISchema, useField, useFieldSchema, useForm } from '@formily/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useActionContext } from '..';
|
import { useActionContext } from '..';
|
||||||
import { useCompile, useDesignable } from '../..';
|
import { useCompile, useDesignable } from '../..';
|
||||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||||
@ -21,7 +22,8 @@ FormItem.Designer = () => {
|
|||||||
const { getField } = useCollection();
|
const { getField } = useCollection();
|
||||||
const field = useField<Field>();
|
const field = useField<Field>();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { dn, reset, refresh } = useDesignable();
|
const { t } = useTranslation();
|
||||||
|
const { dn, refresh } = useDesignable();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const collectionField = getField(fieldSchema['name']);
|
const collectionField = getField(fieldSchema['name']);
|
||||||
const originalTitle = collectionField?.uiSchema?.title;
|
const originalTitle = collectionField?.uiSchema?.title;
|
||||||
@ -60,12 +62,6 @@ FormItem.Designer = () => {
|
|||||||
'x-component-props': {},
|
'x-component-props': {},
|
||||||
description: `原字段标题:${collectionField?.uiSchema?.title}`,
|
description: `原字段标题:${collectionField?.uiSchema?.title}`,
|
||||||
},
|
},
|
||||||
required: {
|
|
||||||
'x-decorator': 'FormItem',
|
|
||||||
'x-component': 'Checkbox',
|
|
||||||
'x-content': '必填',
|
|
||||||
'x-hidden': field.readPretty,
|
|
||||||
},
|
|
||||||
footer: {
|
footer: {
|
||||||
type: 'void',
|
type: 'void',
|
||||||
'x-component': 'Action.Modal.Footer',
|
'x-component': 'Action.Modal.Footer',
|
||||||
@ -96,7 +92,7 @@ FormItem.Designer = () => {
|
|||||||
const ctx = useActionContext();
|
const ctx = useActionContext();
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
const { title, required, label } = form.values;
|
const { title } = form.values;
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
['x-uid']: fieldSchema['x-uid'],
|
['x-uid']: fieldSchema['x-uid'],
|
||||||
@ -108,10 +104,6 @@ FormItem.Designer = () => {
|
|||||||
schema['title'] = title;
|
schema['title'] = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
field.required = required;
|
|
||||||
fieldSchema['required'] = required;
|
|
||||||
schema['required'] = required;
|
|
||||||
|
|
||||||
ctx.setVisible(false);
|
ctx.setVisible(false);
|
||||||
dn.emit('patch', {
|
dn.emit('patch', {
|
||||||
schema,
|
schema,
|
||||||
@ -129,6 +121,24 @@ FormItem.Designer = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{!field.readPretty && (
|
||||||
|
<SchemaSettings.SwitchItem
|
||||||
|
title={t('Required')}
|
||||||
|
checked={field.required}
|
||||||
|
onChange={(required) => {
|
||||||
|
const schema = {
|
||||||
|
['x-uid']: fieldSchema['x-uid'],
|
||||||
|
};
|
||||||
|
field.required = required;
|
||||||
|
fieldSchema['required'] = required;
|
||||||
|
schema['required'] = required;
|
||||||
|
dn.emit('patch', {
|
||||||
|
schema,
|
||||||
|
});
|
||||||
|
refresh();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{collectionField?.target && (
|
{collectionField?.target && (
|
||||||
<SchemaSettings.SelectItem
|
<SchemaSettings.SelectItem
|
||||||
title={'标题字段'}
|
title={'标题字段'}
|
||||||
|
Loading…
Reference in New Issue
Block a user