2017-03-03 38 views
1

我想爲我的redux-form提交兩部分提交策略。首先,用戶在調用驗證方法的表單上調用submit。迴應可能會有一些警告。我希望用戶看到警告(如果有的話),並且可以選擇繼續執行另一個提交,這將成爲服務器休息API的真正POST。我可以使用redux-form自動調用handleSubmit以響應狀態更改嗎?

如果沒有警告,我希望組件自動提交。我試圖從componentWillReceiveProps方法中解決這個問題。

問題是nextProps.handleSubmit(this.doSubmit2of2);不叫this.doSubmit2of2。執行只是通過該呼叫。

componentWillReceiveProps(nextProps) {   

    //boolean that indicates validation just occured against the server 
    if (nextProps.storeWithValidation) { 

     //the user hit submit, first it was validated, if no issues, go ahead and try to create 
     if (nextProps.storeValidationOk) { 
      //fire off create store 
      nextProps.handleSubmit(this.doSubmit2of2); 
     } 
     else { 
      //there are validation issues of some kind, let the user see them 
      //do nothing here and let the render method do its thing with the props 
     } 
    } 
} 

我發現這裏的討論:https://github.com/erikras/redux-form/issues/67,但在我的情況提交正在發生的事情作爲一個特定的服務器響應的結果。另外,我意識到還有redux-form的驗證功能。我在設計框架公約之外設計得太遠了嗎?

此外,我曾想過重新設計我的服務器api,但我想知道我能用這種當前的方法在服務器響應後自動重新提交。

回答

1

從我所瞭解的你想在服務器響應後遠程提交表單。您可以在此example from the docs之後創建遠程提交。然後,只要你想多次,你可以dispatch(submit('yourFormName'))

+0

謝謝,我實際上是遵循這個解決方案。關鍵似乎是在提交方法中執行分支邏輯。我稍後會發布我的解決方案。 – Dranyar

相關問題