以redux形式:如何检索仍未提交的值 [英] in redux-form: how to retrieve values still not submitted

查看:93
本文介绍了以redux形式:如何检索仍未提交的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个redux-form组件,该组件在第一次加载时从redux存储中获取initialValues并填充该表单.该表格仍未提交. (它是以前提交的,但是在用户浏览器重新加载后,我们从头开始处于新状态).初始值已正确填充.

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)

问题:getFormValues('step1')(state)返回空.表单中没有值,未提交.

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

所以问题是:我可以从尚未使用redux-form提交的表单中获取表单的值吗?

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?

我当然可以做一些变通方法,因为我拥有状态值,但是我想知道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.

推荐答案

我很困惑,值是否为格式?您说初始值已正确填充",这使我认为是,但是getFormValues()除了从Redux返回值外没有做任何其他事情.我建议使用 Redux开发工具来确定表单的状态.

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
        }
    })
)

应该是这样:

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

希望有帮助...

这篇关于以redux形式:如何检索仍未提交的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆