2018-06-03 22:00:27 +08:00
|
|
|
---
|
2018-06-28 16:17:22 +08:00
|
|
|
order: 3
|
2018-06-03 22:00:27 +08:00
|
|
|
title:
|
2018-12-13 22:03:12 +08:00
|
|
|
zh-CN: 抽屉表单
|
|
|
|
en-US: Submit form in drawer
|
2018-06-03 22:00:27 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2018-12-13 22:03:12 +08:00
|
|
|
在抽屉中使用表单。
|
2018-06-03 22:00:27 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2018-12-13 22:03:12 +08:00
|
|
|
Use form in drawer with submit button.
|
2018-06-03 22:00:27 +08:00
|
|
|
|
|
|
|
```jsx
|
2018-11-28 15:00:03 +08:00
|
|
|
import {
|
2018-12-13 22:03:12 +08:00
|
|
|
Drawer, Form, Button, Col, Row, Input, Select, DatePicker, Icon,
|
2018-11-28 15:00:03 +08:00
|
|
|
} from 'antd';
|
2018-06-03 22:00:27 +08:00
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
2018-07-02 12:27:06 +08:00
|
|
|
class DrawerForm extends React.Component {
|
2018-06-03 22:00:27 +08:00
|
|
|
state = { visible: false };
|
2018-07-04 08:29:42 +08:00
|
|
|
|
2018-06-03 22:00:27 +08:00
|
|
|
showDrawer = () => {
|
|
|
|
this.setState({
|
2018-06-28 16:17:22 +08:00
|
|
|
visible: true,
|
2018-06-03 22:00:27 +08:00
|
|
|
});
|
|
|
|
};
|
2018-07-04 08:29:42 +08:00
|
|
|
|
2018-06-03 22:00:27 +08:00
|
|
|
onClose = () => {
|
2018-08-05 14:28:39 +08:00
|
|
|
this.setState({
|
|
|
|
visible: false,
|
|
|
|
});
|
2018-06-03 22:00:27 +08:00
|
|
|
};
|
2018-07-04 08:29:42 +08:00
|
|
|
|
2018-06-03 22:00:27 +08:00
|
|
|
render() {
|
|
|
|
const { getFieldDecorator } = this.props.form;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Button type="primary" onClick={this.showDrawer}>
|
2018-12-13 22:03:12 +08:00
|
|
|
<Icon type="plus" /> New account
|
2018-06-03 22:00:27 +08:00
|
|
|
</Button>
|
|
|
|
<Drawer
|
2018-12-13 22:03:12 +08:00
|
|
|
title="Create a new account"
|
2018-06-03 22:00:27 +08:00
|
|
|
width={720}
|
|
|
|
onClose={this.onClose}
|
|
|
|
visible={this.state.visible}
|
2018-06-28 17:54:03 +08:00
|
|
|
style={{
|
|
|
|
overflow: 'auto',
|
2018-12-13 22:03:12 +08:00
|
|
|
height: 'calc(100% - 108px)',
|
|
|
|
paddingBottom: '108px',
|
2018-06-28 17:54:03 +08:00
|
|
|
}}
|
2018-06-03 22:00:27 +08:00
|
|
|
>
|
|
|
|
<Form layout="vertical" hideRequiredMark>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={12}>
|
2018-06-06 22:55:29 +08:00
|
|
|
<Form.Item label="Name">
|
2018-06-03 22:00:27 +08:00
|
|
|
{getFieldDecorator('name', {
|
2018-12-13 22:03:12 +08:00
|
|
|
rules: [{ required: true, message: 'Please enter user name' }],
|
|
|
|
})(<Input placeholder="Please enter user name" />)}
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
2018-06-06 22:55:29 +08:00
|
|
|
<Form.Item label="Url">
|
2018-06-03 22:00:27 +08:00
|
|
|
{getFieldDecorator('url', {
|
2018-12-13 22:03:12 +08:00
|
|
|
rules: [{ required: true, message: 'Please enter url' }],
|
2018-06-03 22:00:27 +08:00
|
|
|
})(
|
|
|
|
<Input
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
addonBefore="http://"
|
|
|
|
addonAfter=".com"
|
2018-12-13 22:03:12 +08:00
|
|
|
placeholder="Please enter url"
|
2018-06-03 22:00:27 +08:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={12}>
|
2018-06-06 22:55:29 +08:00
|
|
|
<Form.Item label="Owner">
|
2018-06-03 22:00:27 +08:00
|
|
|
{getFieldDecorator('owner', {
|
2018-06-06 22:55:29 +08:00
|
|
|
rules: [{ required: true, message: 'Please select an owner' }],
|
2018-06-03 22:00:27 +08:00
|
|
|
})(
|
2018-06-06 22:55:29 +08:00
|
|
|
<Select placeholder="Please select an owner">
|
|
|
|
<Option value="xiao">Xiaoxiao Fu</Option>
|
|
|
|
<Option value="mao">Maomao Zhou</Option>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
2018-06-06 22:55:29 +08:00
|
|
|
<Form.Item label="Type">
|
2018-06-03 22:00:27 +08:00
|
|
|
{getFieldDecorator('type', {
|
2018-06-06 22:55:29 +08:00
|
|
|
rules: [{ required: true, message: 'Please choose the type' }],
|
2018-06-03 22:00:27 +08:00
|
|
|
})(
|
2018-06-06 22:55:29 +08:00
|
|
|
<Select placeholder="Please choose the type">
|
|
|
|
<Option value="private">Private</Option>
|
|
|
|
<Option value="public">Public</Option>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={12}>
|
2018-06-06 22:55:29 +08:00
|
|
|
<Form.Item label="Approver">
|
2018-06-03 22:00:27 +08:00
|
|
|
{getFieldDecorator('approver', {
|
2018-06-06 22:55:29 +08:00
|
|
|
rules: [{ required: true, message: 'Please choose the approver' }],
|
2018-06-03 22:00:27 +08:00
|
|
|
})(
|
2018-06-06 22:55:29 +08:00
|
|
|
<Select placeholder="Please choose the approver">
|
|
|
|
<Option value="jack">Jack Ma</Option>
|
|
|
|
<Option value="tom">Tom Liu</Option>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
2018-06-06 22:55:29 +08:00
|
|
|
<Form.Item label="DateTime">
|
2018-06-03 22:00:27 +08:00
|
|
|
{getFieldDecorator('dateTime', {
|
2018-06-06 22:55:29 +08:00
|
|
|
rules: [{ required: true, message: 'Please choose the dateTime' }],
|
2018-06-03 22:00:27 +08:00
|
|
|
})(
|
|
|
|
<DatePicker.RangePicker
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
getPopupContainer={trigger => trigger.parentNode}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={24}>
|
2018-06-22 15:46:21 +08:00
|
|
|
<Form.Item label="Description">
|
2018-06-06 22:55:29 +08:00
|
|
|
{getFieldDecorator('description', {
|
2018-06-19 17:42:25 +08:00
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
required: true,
|
|
|
|
message: 'please enter url description',
|
|
|
|
},
|
|
|
|
],
|
2018-06-06 22:55:29 +08:00
|
|
|
})(<Input.TextArea rows={4} placeholder="please enter url description" />)}
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Form>
|
2018-06-19 17:42:25 +08:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
2018-12-13 22:03:12 +08:00
|
|
|
left: 0,
|
2018-06-19 17:42:25 +08:00
|
|
|
bottom: 0,
|
|
|
|
width: '100%',
|
2018-12-13 22:03:12 +08:00
|
|
|
borderTop: '1px solid #e9e9e9',
|
2018-06-19 17:42:25 +08:00
|
|
|
padding: '10px 16px',
|
2018-06-28 17:54:03 +08:00
|
|
|
background: '#fff',
|
2018-12-13 22:03:12 +08:00
|
|
|
textAlign: 'right',
|
2018-06-19 17:42:25 +08:00
|
|
|
}}
|
|
|
|
>
|
2018-12-13 22:03:12 +08:00
|
|
|
<Button onClick={this.onClose} style={{ marginRight: 8 }}>
|
2018-06-30 12:32:55 +08:00
|
|
|
Cancel
|
2018-06-19 17:42:25 +08:00
|
|
|
</Button>
|
2018-12-13 22:03:12 +08:00
|
|
|
<Button onClick={this.onClose} type="primary">
|
|
|
|
Submit
|
|
|
|
</Button>
|
2018-06-19 17:42:25 +08:00
|
|
|
</div>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Drawer>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 14:28:39 +08:00
|
|
|
|
2018-07-02 12:27:06 +08:00
|
|
|
const App = Form.create()(DrawerForm);
|
2018-06-03 22:00:27 +08:00
|
|
|
|
2018-07-02 12:27:06 +08:00
|
|
|
ReactDOM.render(<App />, mountNode);
|
2018-06-03 22:00:27 +08:00
|
|
|
```
|