Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access the value of the component #127

Open
tax opened this issue Sep 8, 2015 · 5 comments
Open

How to access the value of the component #127

tax opened this issue Sep 8, 2015 · 5 comments

Comments

@tax
Copy link

tax commented Sep 8, 2015

Really stupid question what is the correct way to access the value of the input text after a value is set by the user?

<Typeahead
   ref="myinput"
   options={this.state.blaat}
   maxVisible={4}
/>
@tax
Copy link
Author

tax commented Sep 8, 2015

One solution I found:

console.log(React.findDOMNode(this.refs.myinput.refs.entry).value);

@codewithcheese
Copy link

I trying to figure that also, you method seems the most logical so far. except I would write it like this:
this.refs.myinput.refs.entry.getDOMNode().value

@juanmnl
Copy link

juanmnl commented Oct 19, 2015

Got the value of the input by binding the onChange event:

<Typeahead
  options={apps}
  maxVisible={10}
  placeholder="Search"
  onChange={this.props.onSearched.bind(null, event)}
  />

And then on the parent component:

render: function() {
  return (
    <Search
      apps={this.state.appsCollection}
      onSearched={this._onSearched}
      />
  );
},

_onSearched: function(event) {
  console.log(event.target.value);
}

Hope this helps 😄

@lgiraudel
Copy link

You can retrieve the value through the component state:

this.refs.myInput.state.entryValue;

@thehuey
Copy link
Contributor

thehuey commented Dec 4, 2015

+1 Use the state.entryValue.

Don't make your code brittle by relying on underlying DOM structure

On Fri, Dec 4, 2015 at 2:56 PM, Loïc Giraudel [email protected]
wrote:

You can retrieve the value through the component state:

this.refs.myInput.state.entryValue;


Reply to this email directly or view it on GitHub
#127 (comment)
.

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

No branches or pull requests

6 participants