Search code examples
redux-form

Redux-Form will not submit if more than one Field


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

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

The following code will not show the alert :

//@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 :

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'
                />
        </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.


Solution

  • 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/