-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { Component } from 'react'; | ||
import { Modal, Form, Input } from 'antd'; | ||
|
||
const FormItem = Form.Item; | ||
|
||
class UserEditModal extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
visible: false, | ||
}; | ||
} | ||
|
||
showModelHandler = (e) => { | ||
if (e) e.stopPropagation(); | ||
this.setState({ | ||
visible: true, | ||
}); | ||
}; | ||
|
||
hideModelHandler = () => { | ||
this.setState({ | ||
visible: false, | ||
}); | ||
}; | ||
|
||
okHandler = () => { | ||
const { onOk } = this.props; | ||
this.props.form.validateFields((err, values) => { | ||
if (!err) { | ||
onOk(values); | ||
this.hideModelHandler(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
}); | ||
}; | ||
|
||
render() { | ||
const { children } = this.props; | ||
const { getFieldDecorator } = this.props.form; | ||
const { name, email, website } = this.props.record; | ||
const formItemLayout = { | ||
labelCol: { span: 6 }, | ||
wrapperCol: { span: 14 }, | ||
}; | ||
|
||
return ( | ||
<span> | ||
<span onClick={this.showModelHandler}> | ||
{ children } | ||
</span> | ||
<Modal | ||
title="Edit User" | ||
visible={this.state.visible} | ||
onOk={this.okHandler} | ||
onCancel={this.hideModelHandler} | ||
> | ||
<Form horizontal onSubmit={this.okHandler}> | ||
This comment has been minimized.
Sorry, something went wrong.
xuyingnan
|
||
<FormItem | ||
{...formItemLayout} | ||
label="Name" | ||
> | ||
{ | ||
getFieldDecorator('name', { | ||
initialValue: name, | ||
})(<Input />) | ||
} | ||
</FormItem> | ||
<FormItem | ||
{...formItemLayout} | ||
label="Email" | ||
> | ||
{ | ||
getFieldDecorator('email', { | ||
initialValue: email, | ||
})(<Input />) | ||
} | ||
</FormItem> | ||
<FormItem | ||
{...formItemLayout} | ||
label="Website" | ||
> | ||
{ | ||
getFieldDecorator('website', { | ||
initialValue: website, | ||
})(<Input />) | ||
} | ||
</FormItem> | ||
</Form> | ||
</Modal> | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
export default Form.create()(UserEditModal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
如果在这里调用 hideModelHandler() , 会不会表单没成功 , 但是对话框已经消失?