Кнопка удаленной отправки Redux Form не работает - PullRequest
0 голосов
/ 07 мая 2020

Я пытаюсь создать кнопку удаленной отправки для моей формы redux, я следил за официальным c об этом, но это не работает для меня, вот компонент формы:

function submit (values) {
console.log('submit');

}

const SurveyForm =({error, handleSubmit}) => {

    return (
        <div>
            <form onSubmit={handleSubmit}>
                <div className={styles.form}>
                    <Field
                        key='title'
                        placeholder='Title'
                        name='title'
                        component={SurveyField}
                        type="text"


                    />
                    <Field
                        key='Subject'
                        placeholder='Subject'
                        name='subject'
                        component={SurveyField}
                        type="text"
                    />
                    <Field
                        key='body'
                        placeholder='Email Body'
                        name='body'
                        component={SurveyField}
                        type="text"
                    />
                    <Field
                        key='emails'
                        placeholder='Recipient List'
                        name='recipients'
                        component={SurveyField}
                        type="text"
                    />
                </div>
            </form>
        </div>
    );

}

function validate(values) { // values coming from the redux from
    const errors = {};


if(!values.title){
    errors.title= 'You must provide a title';
}
if(!values.subject){
    errors.subject ='You must provide a subject';
}
if(!values.body){
    errors.body ='You must provide a content';
}
if(!values.recipients){
    errors.recipients ='You must provide an email';
}
return errors;
}




export default reduxForm({
  form: 'surveyForm',
  validate,
  onSubmit: submit
})(connect(null,actions)(withRouter(SurveyForm)))

И здесь мне нужна моя кнопка отправки

class Mail extends React.Component {
    state = { visible: false, error:'abc', showForm:true };

    componentDidMount() {

}

showModal = () => {
    this.setState({
        visible: true,
        showForm: true
    });
};

handleOk = e => {
    this.props.dispatch(submit('surveyForm'));

};

handleCancel = e => {
    console.log(e);
    this.setState({
        visible: false,
        showForm: false
    });
};

render(){

    return (
        <div>
            <h1>Mail</h1>
            <br/>
            <br/>
            <Button type="primary" shape="circle" icon={<PlusOutlined />} onClick={this.showModal} />
            <ModalUI
                visible={this.state.visible}
                onOk={this.handleOk} // Here is my submit button 
                onCancel={this.handleCancel}
            >
                <SurveyNew  onSubmit={this.handleOk} showForm={this.state.showForm} onCancel={this.handleCancel} onOk={this.handleOk}/>
            </ModalUI>
        </div>
    );
  }
}

экспорт по умолчанию connect () (withRouter (Mail))

Как вы видите, я использую модальное окно, поэтому мне нужно передать отправить функцию в свойства ОК моего модального

Итак, когда я пытаюсь, это не запускает мою функцию отправки с моим console.log ('submit), кто-то может помочь спасибо

...