繁体   English   中英

如何获得 <Field> redux-form 7.0.0中的值

[英]how to get <Field> values in redux-form 7.0.0

 class Form extends React.Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); } handleClick() { const { Add, noteList } = this.props; Add('this is title's value' , 'this is content's value'); } render() { const { handleSubmit, noteList: { list } } = this.props; return ( <form onSubmit={handleSubmit(this.handleClick)}> <div> <Field className="title" name="title" component="input" type="text" /> </div> <div> <Field className="content" name="content" component="textarea" /> </div> <div> <button type="submit" onClick={(e) => { list ? this.handleClick : e.preventDefault(); }}>add</button> </div> </form> ); } } 

当我点击按钮时,我希望将这两个值添加到一个函数中添加为两个参数来执行异步操作,我应该怎么做,请帮助我

handleClick函数中的字段值可以在onSubmit作为对象获得。

class Form extends React.Component {
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(values) {
    const { Add, noteList } = this.props;
    Add(values.title , values.content);
  }

  render() {
    const { handleSubmit, noteList: { list } } = this.props;
    return (
      <form onSubmit={handleSubmit(this.handleClick)}>
        <div>
          <Field className="title" name="title" component="input" type="text" />
        </div>
        <div>
          <Field className="content" name="content" component="textarea" />
        </div>
        <div>
          <button type="submit" onClick={(e) => { list ? this.handleClick : e.preventDefault(); }}>add</button>
        </div>
      </form>
    );
  }
}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM