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-10 18:59:37 +08:00
|
|
|
zh-CN: 抽屉表单
|
|
|
|
en-US: Submit form in drawer
|
2018-06-03 22:00:27 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2018-12-10 18:59:37 +08:00
|
|
|
在抽屉中使用表单。
|
2018-06-03 22:00:27 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2019-04-19 20:59:45 +08:00
|
|
|
Use a form in Drawer with a submit button.
|
2018-06-03 22:00:27 +08:00
|
|
|
|
|
|
|
```jsx
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Drawer, Form, Button, Col, Row, Input, Select, DatePicker } from 'antd';
|
2019-11-28 12:34:33 +08:00
|
|
|
import { PlusOutlined } from '@ant-design/icons';
|
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() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Button type="primary" onClick={this.showDrawer}>
|
2019-11-28 12:34:33 +08:00
|
|
|
<PlusOutlined /> New account
|
2018-06-03 22:00:27 +08:00
|
|
|
</Button>
|
|
|
|
<Drawer
|
2018-12-10 18:59:37 +08:00
|
|
|
title="Create a new account"
|
2018-06-03 22:00:27 +08:00
|
|
|
width={720}
|
|
|
|
onClose={this.onClose}
|
|
|
|
visible={this.state.visible}
|
2019-11-15 17:23:14 +08:00
|
|
|
bodyStyle={{ paddingBottom: 80 }}
|
2020-01-06 14:56:00 +08:00
|
|
|
footer={
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
textAlign: 'right',
|
|
|
|
}}
|
|
|
|
>
|
2020-01-17 23:32:56 +08:00
|
|
|
<Button
|
|
|
|
onClick={this.onClose}
|
|
|
|
style={{ marginRight: 8 }}
|
|
|
|
>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
2020-01-06 14:56:00 +08:00
|
|
|
<Button onClick={this.onClose} type="primary">
|
|
|
|
Submit
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
}
|
2018-06-03 22:00:27 +08:00
|
|
|
>
|
|
|
|
<Form layout="vertical" hideRequiredMark>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={12}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Form.Item
|
|
|
|
name="name"
|
|
|
|
label="Name"
|
|
|
|
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}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Form.Item
|
|
|
|
name="url"
|
|
|
|
label="Url"
|
|
|
|
rules={[{ required: true, message: 'Please enter url' }]}
|
|
|
|
>
|
|
|
|
<Input
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
addonBefore="http://"
|
|
|
|
addonAfter=".com"
|
|
|
|
placeholder="Please enter url"
|
|
|
|
/>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={12}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Form.Item
|
|
|
|
name="owner"
|
|
|
|
label="Owner"
|
|
|
|
rules={[{ required: true, message: 'Please select an owner' }]}
|
|
|
|
>
|
|
|
|
<Select placeholder="Please select an owner">
|
|
|
|
<Option value="xiao">Xiaoxiao Fu</Option>
|
|
|
|
<Option value="mao">Maomao Zhou</Option>
|
|
|
|
</Select>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Form.Item
|
|
|
|
name="type"
|
|
|
|
label="Type"
|
|
|
|
rules={[{ required: true, message: 'Please choose the type' }]}
|
|
|
|
>
|
|
|
|
<Select placeholder="Please choose the type">
|
|
|
|
<Option value="private">Private</Option>
|
|
|
|
<Option value="public">Public</Option>
|
|
|
|
</Select>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={12}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Form.Item
|
|
|
|
name="approver"
|
|
|
|
label="Approver"
|
|
|
|
rules={[{ required: true, message: 'Please choose the approver' }]}
|
|
|
|
>
|
|
|
|
<Select placeholder="Please choose the approver">
|
|
|
|
<Option value="jack">Jack Ma</Option>
|
|
|
|
<Option value="tom">Tom Liu</Option>
|
|
|
|
</Select>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Form.Item
|
|
|
|
name="dateTime"
|
|
|
|
label="DateTime"
|
|
|
|
rules={[{ required: true, message: 'Please choose the dateTime' }]}
|
|
|
|
>
|
|
|
|
<DatePicker.RangePicker
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
getPopupContainer={trigger => trigger.parentNode}
|
|
|
|
/>
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={24}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Form.Item
|
|
|
|
name="description"
|
|
|
|
label="Description"
|
|
|
|
rules={[
|
|
|
|
{
|
|
|
|
required: true,
|
|
|
|
message: 'please enter url description',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<Input.TextArea rows={4} placeholder="please enter url description" />
|
2018-06-03 22:00:27 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Form>
|
|
|
|
</Drawer>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 14:28:39 +08:00
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
ReactDOM.render(<DrawerForm />, mountNode);
|
2018-06-03 22:00:27 +08:00
|
|
|
```
|
2019-12-25 18:06:50 +08:00
|
|
|
|
|
|
|
```css
|
|
|
|
.site-form-in-drawer-wrapper {
|
|
|
|
position: absolute;
|
|
|
|
right: 0px;
|
|
|
|
bottom: 0px;
|
|
|
|
width: 100%;
|
|
|
|
padding: 10px 16px;
|
|
|
|
border-top: 1px solid #e9e9e9;
|
|
|
|
background: #fff;
|
|
|
|
text-align: right;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
<style>
|
|
|
|
[data-theme="dark"] .site-form-in-drawer-wrapper {
|
|
|
|
border-top: 1px solid #303030;
|
|
|
|
background: #1f1f1f;
|
|
|
|
}
|
|
|
|
</style>
|