8

I am not able to access the value of <TextField />, if i don't write <input type='password'/> 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

4 Answers 4

24

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 
Sign up to request clarification or add additional context in comments.

Comments

19

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); 

3 Comments

Cannot find fv, using hooks
How you using hooks here ?
I suggest better to use onChange event rather follow this approach. As React says use onChange event to get values
0

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.

Comments

0

You can get the input value like this :

this.refs.password.input.value; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.