Created
April 14, 2016 08:13
-
-
Save DanielMSchmidt/bfd1860685bdc079bd49921d286c3623 to your computer and use it in GitHub Desktop.
redux-form + autofill
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
@reduxForm({ | |
form: 'login', | |
fields: ['email', 'password'], | |
validate: validation // email and password are both required | |
}) | |
class LoginForm extends Component { | |
static propTypes = { | |
fields: PropTypes.object.isRequired, | |
handleSubmit: PropTypes.func.isRequired, | |
} | |
componentDidMount() { | |
const { | |
email, | |
password, | |
} = this.props.fields; | |
email.onChange(this.refs.email.getValue()); | |
password.onChange(this.refs.password.getValue()); | |
} | |
render() { | |
const { | |
handleSubmit, | |
fields: { | |
email, | |
password | |
} | |
} = this.props; | |
return ( | |
<form onSubmit={handleSubmit}> | |
<Row> | |
<Input | |
ref="email" | |
type="text" | |
{...email} /> | |
<Input | |
ref="password" | |
type="password" | |
{...password} /> | |
</Row> | |
<Button type="submit"> | |
... | |
</Button> | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you manage to get this working? I'm not sure whether I have misunderstood something.
You pass in the array
fields: ['email', 'password']
to the redux form decorator but then define it in the PropTypes as being of type,PropTypes.object.isRequired
. As such, when you use the,email.onChange(...)
callback it is being called on an element in thefields
array which is just a string.I've looked at the docs for Redux forms and couldn't find any mention of being able to pass in the fields property to the decorator...