question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getRenderedComponent() method returns TextField instead of <input />

See original GitHub issue

When i am trying to get rendered component by using method getRenderedComponent() it returns TextField which is passed as component to Field as follows-

<Field type="text" onKeyUp={this.focusNextField} ref="dateFieldRef" withRef maxLength="2" className="form-control zero-padding background-yellow-white" component={TextField} id="date" name="date" placeholder={Strings.day}/> While i pass ‘input’ as component in this upper snippet it just works fine since getRenderedComponent() returns input element.

I tried to access the focus method as follows- this.refs.monthFieldRef.getRenderedComponent().getRenderedComponent().focus(); but it fails with following error- Uncaught TypeError: this.refs.monthFieldRef.getRenderedComponent(...).getRenderedComponent is not a function

I want to access the focus() method of the underlying input element. How am i suppose to call focus() on this TextField component or i am missing something? I am using redux-form v6.6.3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

13reactions
romseguycommented, Jul 8, 2017

I struggled a bit with this so here’s the full solution:

@reduxForm({...})
class Form extends Component {
  focus() {
    this.foo.getRenderedComponent().focusInput()
  }

  render() {
    return (
      <Field
        name="foo"
        component={CustomField}
        type="text"
        ref={node => this.foo = node}
        withRef
      />
    )
  }
}

and

class CustomField extends Component {
  focusInput() {
    this.input.focus()
  }

  render() {
    const {
      input,
      type,
      meta: {touched, error}
    } = this.props

    return (
      <UIForm.Field error={touched && error}>
        <input {...input} ref={node => this.input = node} type={type}/>
      </UIForm.Field>
    )
  }
}
1reaction
gear54ruscommented, Nov 24, 2017

@gustavohenke the thing above needs to be in docs, it really puts things into perspective.

@romseguy thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

redux-form-material-ui using getRenderedComponent ...
I'm passing focus and withRef properties ONLY for first field with error. On this field I always get an error: Uncaught (in promise)...
Read more >
Field - Redux Form
The Field component is how you connect each individual input to the Redux store. ... component will be available with the getRenderedComponent() method....
Read more >
Tips And Tricks For Making The Most Of TextFields In SwiftUI
In SwiftUI TextField is the goto View for capturing freeform input ... if a user taps away from your TextField instead of pressing...
Read more >
Redux-form-antd NPM | npm.io
getRenderedComponent(). Returns a reference to the UI component that has been rendered. This is useful for calling instance methods on the UI components....
Read more >
@jcoreio/redux-form-material-ui - npm
getRenderedComponent(). Returns a reference to the Material UI component that has been rendered. This is useful for calling instance methods on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found