Created
November 16, 2018 17:02
-
-
Save aofleejay/cd9ef81b186a6956e5b0440b2766d29f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React, { Component } from 'react' | |
import { Form, Input } from 'antd' | |
class App extends Component { | |
handleSubmit = (e) => { | |
e.preventDefault() | |
this.props.form.validateFields((err, values) => { | |
if (!err) { | |
console.log('Received values of form: ', values) | |
} | |
}) | |
} | |
onChangeUsername = (e) => { | |
this.props.form.setFieldsValue({ username: e.target.value }) | |
} | |
logCurrentUsername = () => { | |
console.log(this.props.form.getFieldValue('username')) | |
} | |
render() { | |
const { getFieldDecorator } = this.props.form | |
return ( | |
<div> | |
<Form onSubmit={this.handleSubmit}> | |
<Form.Item> | |
{getFieldDecorator('username', { | |
initialValue: 'initial username', | |
rules: [{ required: true, message: 'Please input your username!' }], | |
})(<Input placeholder="Username" onChange={this.onChangeUsername} />)} | |
</Form.Item> | |
</Form> | |
<button onClick={this.logCurrentUsername}> | |
Log username | |
</button> | |
</div> | |
) | |
} | |
} | |
const Wrapper = Form.create()(App) | |
export default Wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment