Reputation: 359
How can I focus on a particular form field after a form submission?
Things already tried:
1.
dispatch(focus('fieldRefName'))
2.
componentWillReceiveProps = (nextProps) => {
if (nextProps.submitting) {
this.refs.fieldRefname.focus()
}
}
I also want to clean the form too after submission.
redux-form version: 3.0.12
Upvotes: 1
Views: 1441
Reputation: 7272
The focus()
action has no effect on the DOM. It's a reaction to the onFocus
event from the DOM. You will need to use this.refs.myField.focus()
.
To clean the form, after submit...
<form onSubmit={this.props.handleSubmit(values => {
return doSubmit(values).then(() => this.props.reset())
}}>
...
</form>
Upvotes: 1