2016-04-12 16:12:13 +08:00
|
|
|
|
---
|
|
|
|
|
order: 14
|
2016-08-02 09:34:04 +08:00
|
|
|
|
title:
|
2016-07-31 09:53:51 +08:00
|
|
|
|
zh-CN: 与 Modal 配合使用
|
2016-09-14 10:25:44 +08:00
|
|
|
|
en-US: With Modal
|
2016-04-12 16:12:13 +08:00
|
|
|
|
---
|
2016-04-12 15:18:57 +08:00
|
|
|
|
|
2016-07-31 09:53:51 +08:00
|
|
|
|
## zh-CN
|
|
|
|
|
|
2016-04-12 15:18:57 +08:00
|
|
|
|
在 Modal 中使用 Form,当点击 Modal 的确定时,调用 `this.props.form.getFieldsValue` 获取表单内的值。
|
|
|
|
|
|
2016-07-31 09:53:51 +08:00
|
|
|
|
## en-US
|
|
|
|
|
|
2016-08-02 09:34:04 +08:00
|
|
|
|
If you use Form in Modal, when you click the Modal, it could invoke `this.props.form.getFieldsValue` to get values of form.
|
2016-07-31 09:53:51 +08:00
|
|
|
|
|
2016-04-12 15:18:57 +08:00
|
|
|
|
````jsx
|
|
|
|
|
import { Button, Form, Input, Modal } from 'antd';
|
|
|
|
|
const createForm = Form.create;
|
|
|
|
|
const FormItem = Form.Item;
|
|
|
|
|
|
|
|
|
|
let Demo = React.createClass({
|
|
|
|
|
getInitialState() {
|
|
|
|
|
return { visible: false };
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleSubmit() {
|
|
|
|
|
console.log(this.props.form.getFieldsValue());
|
|
|
|
|
this.hideModal();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showModal() {
|
|
|
|
|
this.setState({ visible: true });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
hideModal() {
|
|
|
|
|
this.setState({ visible: false });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
render() {
|
2016-09-01 11:48:38 +08:00
|
|
|
|
const { getFieldDecorator } = this.props.form;
|
2016-04-12 15:18:57 +08:00
|
|
|
|
|
|
|
|
|
const formItemLayout = {
|
|
|
|
|
labelCol: { span: 4 },
|
|
|
|
|
wrapperCol: { span: 20 },
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2016-09-18 14:30:37 +08:00
|
|
|
|
<Button type="primary" onClick={this.showModal}>Surprise</Button>
|
2016-07-31 09:53:51 +08:00
|
|
|
|
<Modal title="login" visible={this.state.visible} onOk={this.handleSubmit} onCancel={this.hideModal}>
|
2016-09-09 13:55:46 +08:00
|
|
|
|
<Form horizontal>
|
2016-04-12 15:18:57 +08:00
|
|
|
|
<FormItem
|
|
|
|
|
{...formItemLayout}
|
2016-07-31 09:53:51 +08:00
|
|
|
|
label="User name"
|
2016-06-06 13:54:10 +08:00
|
|
|
|
>
|
2016-09-01 11:48:38 +08:00
|
|
|
|
{getFieldDecorator('username')(
|
|
|
|
|
<Input type="text" autoComplete="off" />
|
|
|
|
|
)}
|
2016-04-12 15:18:57 +08:00
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem
|
|
|
|
|
{...formItemLayout}
|
2016-07-31 09:53:51 +08:00
|
|
|
|
label="Password"
|
2016-06-06 13:54:10 +08:00
|
|
|
|
>
|
2016-09-01 11:48:38 +08:00
|
|
|
|
{getFieldDecorator('password')(
|
|
|
|
|
<Input type="password" autoComplete="off" />
|
|
|
|
|
)}
|
2016-04-12 15:18:57 +08:00
|
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
|
|
|
|
</Modal>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2016-05-11 09:32:33 +08:00
|
|
|
|
},
|
2016-04-12 15:18:57 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Demo = createForm()(Demo);
|
|
|
|
|
|
|
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
|
|
|
|
````
|