1

I would like to make my redux-form fields 'active' by default. Is there a way to do this using RF v.6.5.0 ? Thank you!

Trey Granderson
  • 670
  • 3
  • 8
  • 19

1 Answers1

2

At the moment I don't think there is a property to set on refux-form Fields to set it to active by default. You can set it via refs once the component is mounted though.

Edit: Here might be a cleaner implementation using getRenderedComponent()

componentDidMount() {
  this.refs.defaultInput
    .getRenderedComponent()
    .focus()
}

<Field name="defaultInput" ref="defaultInput" withRef component="input"/>

From redux-form Github There are a few other examples and link in that Github issue.

Yo Wakita
  • 5,322
  • 3
  • 24
  • 36
  • attempted your solution as well as reading through the Redux-Form Github issue you referenced, but still unable to get it working. Used the code above verbatim however this.refs.defaultInput is undefined in componentDidMount. – Trey Granderson Feb 25 '17 at 17:06
  • Are you using a custom input component or a standard `input`? – Yo Wakita Feb 25 '17 at 17:22
  • Custom input. You can view the code I'm attempting here: http://stackoverflow.com/questions/42459190/how-to-use-react-refs-to-focus-a-redux-form-field – Trey Granderson Feb 25 '17 at 17:28
  • I see, can you post the custom input code either here and/or in the other question? – Yo Wakita Feb 25 '17 at 17:46