2021-05-23 08:38:08 +08:00
|
|
|
---
|
|
|
|
title: Form - 表单
|
|
|
|
nav:
|
2021-06-27 15:41:40 +08:00
|
|
|
title: 组件
|
|
|
|
path: /client
|
2021-05-23 08:38:08 +08:00
|
|
|
group:
|
2021-06-27 15:41:40 +08:00
|
|
|
order: 1
|
2021-07-08 14:21:18 +08:00
|
|
|
title: Schemas
|
|
|
|
path: /client/schemas
|
2021-05-23 08:38:08 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
# Form - 表单
|
|
|
|
|
2021-07-14 08:43:18 +08:00
|
|
|
## Node Tree
|
2021-07-13 00:31:38 +08:00
|
|
|
|
|
|
|
<pre lang="tsx">
|
|
|
|
<Form>
|
|
|
|
<Input/>
|
|
|
|
<Select/>
|
|
|
|
// 添加其他节点
|
|
|
|
</Form>
|
2021-07-14 08:43:18 +08:00
|
|
|
|
2021-07-21 21:51:16 +08:00
|
|
|
<Form>
|
|
|
|
// Form.Field 可用于覆盖字段原配置,但不修改原字段配置,新配置只作用于当前 Form
|
|
|
|
<Form.Field title={'自定义标题'}>
|
|
|
|
<Input title={'原标题'}>
|
|
|
|
</Form.Field>
|
|
|
|
</Form>
|
|
|
|
|
2021-07-15 18:47:21 +08:00
|
|
|
// Form 用作 decorator 时只用于创建独立的作用域
|
2021-07-14 08:43:18 +08:00
|
|
|
<Table x-decorator={'Form'}/>
|
2021-07-13 00:31:38 +08:00
|
|
|
</pre>
|
|
|
|
|
2021-07-14 08:43:18 +08:00
|
|
|
## Designable Bar
|
|
|
|
|
|
|
|
- Form.DesignableBar
|
|
|
|
|
|
|
|
## Examples
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
### 常规表单
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
```tsx
|
|
|
|
import React from 'react';
|
2021-07-04 00:19:26 +08:00
|
|
|
import { SchemaRenderer } from '../';
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
const schema = {
|
|
|
|
type: 'object',
|
2021-07-15 18:47:21 +08:00
|
|
|
name: 'form',
|
2021-07-06 00:15:19 +08:00
|
|
|
'x-component': 'Form',
|
2021-07-15 18:47:21 +08:00
|
|
|
'x-component-props': {
|
|
|
|
layout: 'horizontal',
|
|
|
|
},
|
2021-06-27 15:41:40 +08:00
|
|
|
properties: {
|
2021-07-06 00:15:19 +08:00
|
|
|
username: {
|
|
|
|
type: 'string',
|
|
|
|
title: '用户名',
|
|
|
|
required: true,
|
|
|
|
'x-decorator': 'FormItem',
|
2021-07-15 18:47:21 +08:00
|
|
|
'x-designable-bar': 'FormItem.DesignableBar',
|
2021-07-06 00:15:19 +08:00
|
|
|
'x-component': 'Input',
|
|
|
|
},
|
|
|
|
password: {
|
|
|
|
type: 'string',
|
|
|
|
title: '密码',
|
|
|
|
required: true,
|
|
|
|
'x-decorator': 'FormItem',
|
|
|
|
'x-component': 'Password',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
2021-06-27 15:41:40 +08:00
|
|
|
|
|
|
|
export default () => {
|
|
|
|
return (
|
2021-07-15 18:47:21 +08:00
|
|
|
<SchemaRenderer debug={true} schema={schema} />
|
2021-06-27 15:41:40 +08:00
|
|
|
);
|
|
|
|
};
|
2021-05-23 08:38:08 +08:00
|
|
|
```
|
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
### 栅格布局表单
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
```tsx
|
|
|
|
import React from 'react';
|
2021-07-04 00:19:26 +08:00
|
|
|
import { SchemaRenderer } from '../';
|
2021-07-04 22:04:15 +08:00
|
|
|
import { uid } from '@formily/shared';
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
const schema = {
|
|
|
|
type: 'void',
|
2021-07-04 22:04:15 +08:00
|
|
|
name: uid(),
|
2021-06-27 15:41:40 +08:00
|
|
|
'x-decorator': 'Card',
|
|
|
|
'x-component': 'Form',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[uid()]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`row_${uid()}`]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid.Row',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`col_${uid()}`]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid.Col',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`block_${uid()}`]: {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
title: '字段1',
|
|
|
|
'x-decorator': 'FormItem',
|
|
|
|
'x-component': 'Input',
|
2021-06-27 15:41:40 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-07-04 22:04:15 +08:00
|
|
|
[`col_${uid()}`]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid.Col',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`block_${uid()}`]: {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
title: '字段2',
|
|
|
|
'x-decorator': 'FormItem',
|
|
|
|
'x-component': 'Input',
|
2021-06-27 15:41:40 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
type: 'void',
|
|
|
|
// 'x-decorator': 'Div',
|
|
|
|
'x-component': 'Space',
|
|
|
|
properties: {
|
|
|
|
submit: {
|
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Action',
|
|
|
|
'x-component-props': {
|
|
|
|
type: 'primary',
|
|
|
|
},
|
|
|
|
title: '提交',
|
|
|
|
},
|
|
|
|
reset: {
|
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Action',
|
2021-07-15 18:47:21 +08:00
|
|
|
'x-component-props': {},
|
2021-06-27 15:41:40 +08:00
|
|
|
title: '重置',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-23 08:38:08 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
export default () => {
|
|
|
|
return (
|
2021-07-04 00:19:26 +08:00
|
|
|
<SchemaRenderer schema={schema} />
|
2021-06-27 15:41:40 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
```
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
### 表单设计器
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
```tsx
|
|
|
|
import React from 'react';
|
2021-07-04 00:19:26 +08:00
|
|
|
import { SchemaRenderer } from '../';
|
2021-06-27 15:41:40 +08:00
|
|
|
import { uid } from '@formily/shared';
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
const schema = {
|
|
|
|
type: 'void',
|
2021-07-04 22:04:15 +08:00
|
|
|
name: uid(),
|
2021-07-14 08:43:18 +08:00
|
|
|
'x-decorator': 'BlockItem',
|
2021-06-27 15:41:40 +08:00
|
|
|
'x-component': 'Form',
|
2021-07-04 22:04:15 +08:00
|
|
|
'x-designable-bar': 'Form.DesignableBar',
|
2021-06-27 15:41:40 +08:00
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[uid()]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`row_${uid()}`]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid.Row',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`col_${uid()}`]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid.Col',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`block_${uid()}`]: {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
title: '字段1',
|
|
|
|
'x-decorator': 'FormItem',
|
|
|
|
'x-designable-bar': 'FormItem.DesignableBar',
|
|
|
|
'x-component': 'Input',
|
2021-06-27 15:41:40 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-07-04 22:04:15 +08:00
|
|
|
[`col_${uid()}`]: {
|
2021-06-27 15:41:40 +08:00
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Grid.Col',
|
|
|
|
properties: {
|
2021-07-04 22:04:15 +08:00
|
|
|
[`block_${uid()}`]: {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
title: '字段2',
|
|
|
|
'x-decorator': 'FormItem',
|
|
|
|
'x-designable-bar': 'FormItem.DesignableBar',
|
|
|
|
'x-component': 'Input',
|
2021-06-27 15:41:40 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
type: 'void',
|
|
|
|
// 'x-decorator': 'Div',
|
|
|
|
'x-component': 'Space',
|
|
|
|
properties: {
|
|
|
|
submit: {
|
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Action',
|
|
|
|
'x-component-props': {
|
|
|
|
type: 'primary',
|
|
|
|
},
|
|
|
|
title: '提交',
|
|
|
|
},
|
|
|
|
reset: {
|
|
|
|
type: 'void',
|
|
|
|
'x-component': 'Action',
|
|
|
|
'x-component-props': {
|
|
|
|
},
|
|
|
|
title: '重置',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-07-04 22:04:15 +08:00
|
|
|
}
|
2021-05-23 08:38:08 +08:00
|
|
|
|
2021-06-27 15:41:40 +08:00
|
|
|
export default () => {
|
|
|
|
return (
|
2021-07-04 00:19:26 +08:00
|
|
|
<SchemaRenderer schema={schema} />
|
2021-06-27 15:41:40 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
```
|