简体   繁体   English

如何在 react 的 material-ui 中获取密码字段值

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

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 '.我无法访问<TextField />的值,如果我不写<input type='password'/>那么它工作正常,但为此我得到一个 TypeError,' this.refs[this. _getRef(...)].getInputNode 不是函数'。

 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.下图是上述代码的控制台输出。

控制台输出

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对于 React v >= 15.6

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

in inputHandler function在 inputHandler 函数中

this.password.value

For material 1.0 and react 16.1.1对于材料 1.0 和反应 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);

Assign ref="password" to the input itself instead of the TextField .ref="password"分配给输入本身而不是TextField Currently you are executing getValue() on some abstract (probably some container) tag ( TextField ), not on the input itself.当前,您正在某个抽象(可能是某个容器)标签( TextField )上执行getValue() ),而不是在input本身上执行。

Here 's how it's done. 是它的完成方式。

您可以像这样获取输入值:

 this.refs.password.input.value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 material-ui 的 TextField 打印 React 中的值 - Print a value in React from material-ui's TextField 如何在 material-ui react 中管理多文本字段验证? - How to manage multi Text Field validation in material-ui react? 如何将Material-UI的快餐栏和输入组件结合在一起进行反应? - How to combine Material-UI's snackbar and input components in react? React:如何从 Material-UI TextField 组件中获取值 - React: How to get values from Material-UI TextField components React Material-UI Autocomplete:如何在更改另一个字段中的值时清除在自动完成字段中选择的多个值(mui 芯片)? - React Material-UI Autocomplete: How to clear multiple values (mui chips) selected in a Autocomplete field on changing the value in another field? 获取 React material-UI 自动完成中的值 - Getting the value in the React material-UI Autocomplete 如何使用 Material-UI 的自动完成功能获得“以选项为中心”的事件? - How to get an "option focused" event with Material-UI's Autocomplete? Material-UI如何在const中获取SelectField的值 - Material-UI how to get the value of SelectField inside const 如何获取 material-ui 的自动完成 Select 的值? - How can I get the value of the Autocomplete Select of material-ui? 如何获取 Material-UI 日期选择器值 - How to get Material-UI Date Picker value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM