How to get password field value in react's material-ui

流过昼夜 提交于 2019-11-30 20:32:46

For material 1.0 and react 16.1.1

Use inputRef

  <TextField autoFocus={true} inputRef={el => this.fv = el} 
        placeholder="Required" size="30"></TextField >

To read the value use below line

console.log(this.fv.value);

This solved my issue:

<TextField ref='password'
    hintText="Password"
    floatingLabelText="Password"
    type="password">
</TextField>

After that

 this.refs.password.getValue()

gives the desired output.

For React v >= 15.6

<TextField ref={x => this.password = x}
    hintText="Password"
    floatingLabelText="Password"
    type="password">
</TextField>

in inputHandler function

this.password.value

Assign ref="password" to the input itself instead of the TextField. Currently you are executing getValue() on some abstract (probably some container) tag (TextField), not on the input itself.

Here's how it's done.

You can get the input value like this :

this.refs.password.input.value;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!