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.
176 lines
5.2 KiB
176 lines
5.2 KiB
7 years ago
|
---
|
||
7 years ago
|
order: 3
|
||
7 years ago
|
title:
|
||
6 years ago
|
zh-CN: 抽屉表单
|
||
|
en-US: Submit form in drawer
|
||
7 years ago
|
---
|
||
|
|
||
|
## zh-CN
|
||
|
|
||
6 years ago
|
在抽屉中使用表单。
|
||
7 years ago
|
|
||
|
## en-US
|
||
|
|
||
6 years ago
|
Use form in drawer with submit button.
|
||
7 years ago
|
|
||
|
```jsx
|
||
6 years ago
|
import {
|
||
6 years ago
|
Drawer, Form, Button, Col, Row, Input, Select, DatePicker, Icon,
|
||
6 years ago
|
} from 'antd';
|
||
7 years ago
|
|
||
|
const { Option } = Select;
|
||
|
|
||
6 years ago
|
class DrawerForm extends React.Component {
|
||
7 years ago
|
state = { visible: false };
|
||
6 years ago
|
|
||
7 years ago
|
showDrawer = () => {
|
||
|
this.setState({
|
||
7 years ago
|
visible: true,
|
||
7 years ago
|
});
|
||
|
};
|
||
6 years ago
|
|
||
7 years ago
|
onClose = () => {
|
||
6 years ago
|
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}>
|
||
6 years ago
|
<Icon type="plus" /> New account
|
||
7 years ago
|
</Button>
|
||
|
<Drawer
|
||
6 years ago
|
title="Create a new account"
|
||
7 years ago
|
width={720}
|
||
|
onClose={this.onClose}
|
||
|
visible={this.state.visible}
|
||
7 years ago
|
style={{
|
||
|
overflow: 'auto',
|
||
6 years ago
|
height: 'calc(100% - 108px)',
|
||
|
paddingBottom: '108px',
|
||
7 years ago
|
}}
|
||
7 years ago
|
>
|
||
|
<Form layout="vertical" hideRequiredMark>
|
||
|
<Row gutter={16}>
|
||
|
<Col span={12}>
|
||
7 years ago
|
<Form.Item label="Name">
|
||
7 years ago
|
{getFieldDecorator('name', {
|
||
6 years ago
|
rules: [{ required: true, message: 'Please enter user name' }],
|
||
|
})(<Input placeholder="Please enter user name" />)}
|
||
7 years ago
|
</Form.Item>
|
||
|
</Col>
|
||
|
<Col span={12}>
|
||
7 years ago
|
<Form.Item label="Url">
|
||
7 years ago
|
{getFieldDecorator('url', {
|
||
6 years ago
|
rules: [{ required: true, message: 'Please enter url' }],
|
||
7 years ago
|
})(
|
||
|
<Input
|
||
|
style={{ width: '100%' }}
|
||
|
addonBefore="http://"
|
||
|
addonAfter=".com"
|
||
6 years ago
|
placeholder="Please enter url"
|
||
7 years ago
|
/>
|
||
|
)}
|
||
|
</Form.Item>
|
||
|
</Col>
|
||
|
</Row>
|
||
|
<Row gutter={16}>
|
||
|
<Col span={12}>
|
||
7 years ago
|
<Form.Item label="Owner">
|
||
7 years ago
|
{getFieldDecorator('owner', {
|
||
7 years ago
|
rules: [{ required: true, message: 'Please select an owner' }],
|
||
7 years ago
|
})(
|
||
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}>
|
||
7 years ago
|
<Form.Item label="Type">
|
||
7 years ago
|
{getFieldDecorator('type', {
|
||
7 years ago
|
rules: [{ required: true, message: 'Please choose the type' }],
|
||
7 years ago
|
})(
|
||
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}>
|
||
7 years ago
|
<Form.Item label="Approver">
|
||
7 years ago
|
{getFieldDecorator('approver', {
|
||
7 years ago
|
rules: [{ required: true, message: 'Please choose the approver' }],
|
||
7 years ago
|
})(
|
||
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}>
|
||
7 years ago
|
<Form.Item label="DateTime">
|
||
7 years ago
|
{getFieldDecorator('dateTime', {
|
||
7 years ago
|
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">
|
||
7 years ago
|
{getFieldDecorator('description', {
|
||
7 years ago
|
rules: [
|
||
|
{
|
||
|
required: true,
|
||
|
message: 'please enter url description',
|
||
|
},
|
||
|
],
|
||
7 years ago
|
})(<Input.TextArea rows={4} placeholder="please enter url description" />)}
|
||
7 years ago
|
</Form.Item>
|
||
|
</Col>
|
||
|
</Row>
|
||
|
</Form>
|
||
7 years ago
|
<div
|
||
|
style={{
|
||
|
position: 'absolute',
|
||
6 years ago
|
left: 0,
|
||
7 years ago
|
bottom: 0,
|
||
|
width: '100%',
|
||
6 years ago
|
borderTop: '1px solid #e9e9e9',
|
||
7 years ago
|
padding: '10px 16px',
|
||
7 years ago
|
background: '#fff',
|
||
6 years ago
|
textAlign: 'right',
|
||
7 years ago
|
}}
|
||
|
>
|
||
6 years ago
|
<Button onClick={this.onClose} style={{ marginRight: 8 }}>
|
||
6 years ago
|
Cancel
|
||
7 years ago
|
</Button>
|
||
6 years ago
|
<Button onClick={this.onClose} type="primary">
|
||
|
Submit
|
||
|
</Button>
|
||
7 years ago
|
</div>
|
||
7 years ago
|
</Drawer>
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
const App = Form.create()(DrawerForm);
|
||
7 years ago
|
|
||
6 years ago
|
ReactDOM.render(<App />, mountNode);
|
||
7 years ago
|
```
|