如果超过一个字段,Redux-Form 将不会提交 [英] Redux-Form will not submit if more than one Field

查看:40
本文介绍了如果超过一个字段,Redux-Form 将不会提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有多个字段时,为什么我的 redux-form 不提交?

Why does my redux-form not submit when I have more than one field?

如果我有多个字段,则表单上的 onSubmit 不会运行.

If I have more than one field then the onSubmit on my form does not run.

以下代码将显示警报:

//@flow
import * as React from 'react';
import {Field, reduxForm, Form} from 'redux-form';


class CustomerPage2 extends React.Component {

    constructor(props) {
        super(props);
    }

    render() {

        let submit = () => alert("show me the money")

        return (
                <Form id="myform" onSubmit={submit} >
                        <Field
                            label={'asdf'}
                            className={'input'}
                            id='1'
                            name={'salutation'}
                            mandatory={true}
                            component='input'
                        />
                        <Field
                            label={'asdf2'}
                            className={'input'}
                            id='2'
                            name={'first_name'}
                            mandatory={true}
                            component='input'
                        />
                </Form>
        );
    }
}

export default reduxForm({
    form: 'customerRegistration',
})(CustomerPage2)

但是,如果我删除其中一个字段,则会弹出警报:

However if I remove one of the fields the alert will pop up :

渲染(){

let submit = () => alert("show me the money")

return (
        <Form id="myform" onSubmit={submit} >
                <Field
                    label={'asdf'}
                    className={'input'}
                    id='1'
                    name={'salutation'}
                    mandatory={true}
                    component='input'
                />
        </Form>
);

}

我还创建了一个小提琴,您可以亲眼看到它:

I also created a fiddle where you can see it for your own eyes :

https://jsfiddle.net/036ur33k/150/

只需删除其中一个字段,您就会明白我的意思.

Just remove one of the fields and you will see what I mean.

推荐答案

我想你忘记在 onSubmit 事件中使用 handleSubmit 函数(redux-form 将它添加到组件 props 上).

I think you forgot to use the handleSubmit function (redux-form adds it on the component props) in your onSubmit event.

我修改了你的小提琴,检查它是否是你需要的.

I modified your fiddle, check if it is what you need.

https://jsfiddle.net/036ur33k/173/

这篇关于如果超过一个字段,Redux-Form 将不会提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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