2017-07-18 45 views
2

我無法在我的提交回調中獲取字段值。相反,我在那裏收到一個事件。 誰能告訴我什麼,我做錯了如何從REDX形式獲取字段值

This is what I am getting in my submit callback

render() { 
 
    const { fields, handleSubmit, submitting, buttonWrapper, btnText } = this.props; 
 
    return (
 
     <form name="AddEvent" onSubmit={handleSubmit}> 
 
     {fields.map(field => (
 
      <div className={field.wrapperClass}> 
 
      <Field 
 
       name={field.name} 
 
       type={field.type || 'text'} 
 
       component={mapComponentClass(field.componentClass)} 
 
       validate={mapValidators(field.validate)} 
 
       props={field.inputProps} 
 
       label={field.label} 
 
      /> 
 
      </div> 
 
     ))} 
 
     <div className="form-submit-wrap container"> 
 
      <button 
 
       type="submit" 
 
       disabled={submitting} 
 
       className="form-submit" 
 
      > 
 
       {submitting ? 'Submitting' : 'Submit'} 
 
      </button> 
 
      </div> 
 
     </form> 
 
    ); 
 
    }

+0

請問您可以添加您的REDX表格代碼 –

+1

當然你會在那裏得到一個活動,這是一個事件。表單值處於狀態。有關如何處理此問題,請參閱redux-form文檔,例如http://redux-form.com/7.0.0/examples/submitValidation/。 –

回答

1

handleSubmit應該是你的onSubmit功能的包裝。

試試這樣說:

<form onSubmit={handleSubmit(onSubmit)}> 
</form> 

現在onSubmit將收到1個參數與所有的表單值。

不是說你自找的,但作爲一個側面說明,如果你願意,你可以觸發從提交驗證錯誤,就像你onSubmit函數中:

throw ReduxForm.SubmissionError({name: 'There\'s something wrong in the name field'}); 

...作爲一個結果,你的Ajax調用使name無效。