如果 Field 超过一个,Redux-Form 将不会提交
Redux-Form will not submit if more than one Field
当我有多个字段时,为什么我的 redux-form 不提交?
如果我有多个字段,那么我表单上的 onSubmit 不会 运行。
以下代码将不会显示警报:
//@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)
但是,如果我删除其中一个字段,则会弹出警报:
渲染(){
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>
);
}
我还创建了一个 fiddle,您可以在其中亲眼看到:
https://jsfiddle.net/036ur33k/150/
只需删除其中一个字段,您就会明白我的意思。
我想你忘了在你的 onSubmit 事件中使用 handleSubmit
函数(redux-form 将它添加到组件属性上)。
我修改了你的fiddle,看看是不是你需要的
当我有多个字段时,为什么我的 redux-form 不提交?
如果我有多个字段,那么我表单上的 onSubmit 不会 运行。
以下代码将不会显示警报:
//@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)
但是,如果我删除其中一个字段,则会弹出警报:
渲染(){
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>
);
}
我还创建了一个 fiddle,您可以在其中亲眼看到:
https://jsfiddle.net/036ur33k/150/
只需删除其中一个字段,您就会明白我的意思。
我想你忘了在你的 onSubmit 事件中使用 handleSubmit
函数(redux-form 将它添加到组件属性上)。
我修改了你的fiddle,看看是不是你需要的