当我有多个字段时,为什么我的redux表单不提交?
如果我有多个字段,那么表单上的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)
但是,如果我删除其中一个字段,警报将弹出:
RelDead(){
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>
);
}
我还做了一把小提琴,你可以用自己的眼睛看到它:
https://jsfiddle.net/036ur33k/150/
只需移除其中一个字段,您就会明白我的意思。