in redux-form: how to retrieve values still not submitted

十年热恋 提交于 2019-12-12 03:40:16

问题


I have a redux-form component which gets initialValues from the redux store in the first load and populates the form. The form is still not submitted. (it was submitted previously but we are in new state from scratch after a user browser reload). The initial Values are populated properly.

let CheckoutStep1Form = (props) => {
   return(
     //my fancy form
   )
}

CheckoutStep1Form = reduxForm({
    form: 'step1', // a unique name for this form
})(CheckoutStep1Form);

CheckoutStep1Form = connect(
    state => ({
        initialValues: {
          //my initial values
        }
    })
)(CheckoutStep1Form)

Besides this I have another component which is aiming to summarise all the form information provided in previous steps in a plain view.

const CheckoutStep1Summary = ({values}) => {
   return(
     //my fancy summarize view
   )
}

export default connect(
    state => ({
        values: getFormValues('step1')(state)
    })
)(CheckoutStep1Summary)

Problem: getFormValues('step1')(state) returns empty. No values in the form due not submitted.

So the question is: Can I get the form Values from a form that it was not already submitted in some way using redux-form?

Of course I could do some workaround as I have the values in the state but I would like to know if redux-form is taking in consideration this scenario.


回答1:


I'm confused, are the values in the form or not? You say "The initial Values are populated properly", which leads me to think yes, but getFormValues() isn't doing anything more than returning the values from Redux. I'd recommend using Redux Dev Tools to suss out just what the form state looks like.

You might have just typed it wrong in this question, but this:

CheckoutStep1Form = connect(
    state => ({
        initialValues: {
          //my initial values
        }
    })
)

should be this:

CheckoutStep1Form = connect(
    state => ({
        initialValues: {
          //my initial values
        }
    })
)(CheckoutStep1Form) // <-------

Hope that helps...



来源:https://stackoverflow.com/questions/42294024/in-redux-form-how-to-retrieve-values-still-not-submitted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!