Vikramaditya Vikramaditya - 6 months ago 189
Javascript Question

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

I am not able to access the value of , if i don't write then it works fine, but for this i am getting a TypeError, 'this.refs[this._getRef(...)].getInputNode is not a function'.

dialogAction(tag,e){

console.log(this.refs.password);
console.log(this.refs.password.getValue());
this.refs.dialog.dismiss();
}

render(){
let self = this;

let row = this.row,col = this.column;
let standardActions = [
{ text: 'Cancel',onTouchTap: this.dialogAction.bind(this,ProductConstants.CANCEL)},
{ text: 'Submit',onTouchTap: this.dialogAction.bind(this,ProductConstants.SUBMIT)}
];

return (
<div className="ProductRepository">

<Dialog ref = 'dialog'
title="Dialog With Standard Actions"
actions={standardActions}
actionFocus="submit"
modal={true}>
<TextField ref='password'
hintText="Password"
floatingLabelText="Password">
<input type="password" />
</TextField>
</Dialog>
</div>
);}

}


image below is the console output of the above code.

console output

Answer

This solved my issue:

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

After that

this.refs.password.getValue()

gives the desired output.

Comments