2017-01-11 25 views
0

从redux-form提供的action创建者调用时,我在Redux-Form中的onSubmit处理程序出现错误。如果我在里面使用常规按钮,它应该可以正常工作。如果提交通过this.props.smit提交('formname')调用onSubmit处理程序的错误

import { Field, reduxForm } from 'redux-form'; 

class Property extends Component { 
    constructor(props) { 
     super(props); 

     this.saveOnChange = this.saveOnChange.bind(this); 
     this.handleSubmit = this.handleSubmit.bind(this); 
    } 

    handleSubmit() { 
     console.log('form submitting'); 
    } 

    saveOnChange() { 
     console.log('should auto save'); 
     this.props.dispatch(this.props.submit('propertySettings')); 
    } 

    render() { 
     const { handleSubmit } = this.props; 

     return(
      <form onSubmit={handleSubmit(this.handleSubmit)}> 
       // Stuff goes here 

       <div onClick={this.saveOnChange}>(just for example it is with a div)</div> // <-- Get's errors 
       <button type='submit'>Via button</button> // <-- Work's fine 
      </form> 
     ); 
    } 
} 

经由动作创建者

enter image description here

+0

如何将行更改为

therewillbecode

+0

@therewillbecode查看更新后的答案,此错误仅在调用与由redux-form提供的操作创建者提交时存在 – NealVDV

回答

1

好像你试图的handleSubmit本地方法绑定到组件的范围,然后把它作为一个呼叫时接收errros对道具的handleSubmit方法的论证。

如果你只是想分配handleSubmit方法窗体的的onsubmit你可以试试这个:从版本终极版形式6.3.x的

import { Field, reduxForm } from 'redux-form'; 

class Property extends Component { 
    constructor(props){ 
    super(props); 
    this.handleSubmit = this.handleSubmit.bind(this); 
    // bind handleSubmit in the constructor, it's more efficient 
    // as it only occurs once per lifetime of a component 
    } 
    handleSubmit() { 
    console.log('form submitting'); 
    } 
    render() { 
    return(
     <form onSubmit= { this.handleSubmit}> // call it here like this 
     // Stuff goes here 
     </form> 
    ); 
    } 
}
+0

使用此I仍然收到相同的错误:/ – NealVDV

+0

我发现只有当您使用操作创建者来调用提交时。查看更新后的问题 – NealVDV

+0

您仍然按照我所建议的方式分配处理提交不同。 – Pineda