You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.1 KiB

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