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

Support for ref's on Input component #2

Closed
mwq27 opened this issue Oct 15, 2014 · 4 comments
Closed

Support for ref's on Input component #2

mwq27 opened this issue Oct 15, 2014 · 4 comments
Labels
PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI

Comments

@mwq27
Copy link
Contributor

mwq27 commented Oct 15, 2014

I'm not able to set a ref attribute on the Input component.

@hai-cea
Copy link
Member

hai-cea commented Oct 15, 2014

Hi @mwq27 - I'm not able to reproduce the issue you're referring to.

I was able to do that following:

/**
 * @jsx React.DOM
 */

var React = require('react'),
  mui = require('material-ui');

var myComponent = React.createClass({

  componentDidMount: function() {
    console.log(this.refs.firstname.getDOMNode());
  },

  render: function() {
    return (
        <mui.Input ref="firstname" type="text" name="firstname" placeholder="First Name" description="Your first name as it appears on your credit card." />
    );
  }

});

module.exports = MyComponent;

@mwq27
Copy link
Contributor Author

mwq27 commented Oct 15, 2014

So I have

console.log(this.refs.firstname.getDOMNode().value) 

that is returning undefined, even after I add text to the input. this.refs.firstname.getDOMNode() by itself is the div that gets created in Input.jsx, so I guess it wouldn't have a .value property.

@hai-cea
Copy link
Member

hai-cea commented Oct 15, 2014

Ahh yes. You're right. I've updated the input component to handle this.

Now you can do:

render: function() {
    return (
        <mui.Input ref="firstname" defaultValue="Test" onChange={this._onChange} />
    );
},

//onChange now passes back the new value as a second parameter
_onChange: function(e, value) {
  console.log(value);

  //Or you can do this elsewhere in your component
  console.log(this.refs.firstname.getValue());
}

@mwq27
Copy link
Contributor Author

mwq27 commented Oct 16, 2014

ok great, thank you :)

@mwq27 mwq27 closed this as completed Oct 16, 2014
hai-cea pushed a commit that referenced this issue Dec 20, 2014
nathanmarks pushed a commit to nathanmarks/material-ui that referenced this issue Apr 9, 2016
[Chip] Add more tests, change Avatar type checking for more flexibili…
@muibot muibot added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Jul 8, 2016
nathanmarks pushed a commit to nathanmarks/material-ui that referenced this issue Jul 8, 2016
modalManager and space after colon linting
DavidNgv added a commit to DavidNgv/material-ui that referenced this issue Dec 6, 2016
gabrieldeal added a commit to dicksonlabs/material-ui that referenced this issue Dec 29, 2016
Add a callback property that is called whenever the MenuItem focus is changed.

Sometimes it will be called when the focus isn't changed.  For example:
* If top menu item is keyboard focused (call mui#1) and then the up arrow is pressed (call mui#2).
* If some menu item is keyboard focused (call mui#1) and then that same menu item is clicked (call mui#2).
antoniogiordano added a commit to Ubiatar/material-ui that referenced this issue Sep 22, 2018
antoniogiordano added a commit to Ubiatar/material-ui that referenced this issue Nov 14, 2018
eps1lon pushed a commit that referenced this issue Jun 19, 2020
bharatkashyap added a commit to bharatkashyap/material-ui that referenced this issue Dec 2, 2021
# This is the 1st commit message:

[docs] load Jarle preview, simple-react-code-editor on static demo click

# This is the commit message mui#2:

show full source with edited changes
abaker93 added a commit to abaker93/material-ui that referenced this issue Apr 15, 2022
links weren't linking to correct anchors. Fixed and updated name of mui#2 from "reusable style overrides" to "reusable component"
DiegoAndai referenced this issue in DiegoAndai/material-ui Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI
Projects
None yet
Development

No branches or pull requests

3 participants