簡體   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