Skip to content

Instantly share code, notes, and snippets.

@DanielMSchmidt
Created April 14, 2016 08:13
Show Gist options
  • Save DanielMSchmidt/bfd1860685bdc079bd49921d286c3623 to your computer and use it in GitHub Desktop.
Save DanielMSchmidt/bfd1860685bdc079bd49921d286c3623 to your computer and use it in GitHub Desktop.
redux-form + autofill
@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>
);
}
}
@shooftie
Copy link

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 the fields 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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment