I have a handler on my button, in which I need to get the form values, validate them and if everything is fine, send a post request.

onMyClick() { const {store} = this.context; const state = store.getState(); let data = getFormValues('form-id')(state); // получаем значения формы data.is_draft = true; let errors = validate(data); //моя функция валидации this.handleFormSubmit(data); // функция отправки данных на сервер } 

The problem is that if the errors are non-empty, then we must somehow highlight the fields on the form. It all works automatically for the button type, but how to do it manually? What method redux form need to call?

    1 answer 1

    To do this, use the submit action generator.

     import { submit } from 'redux-form' handleClick () { const { dispatch } = this.props dispatch(submit('remoteSubmit')) } 

    For a more detailed example: https://redux-form.com/7.2.3/examples/remotesubmit/

    • This error falls if you do this: "you must either pass handleSubmit () an onSubmit function or pass onSubmit as a prop" - kidar2
    • @ kidar2 handleSubmit needs to be passed to the form component via props. - Maxim T
    • It is transmitted. I found out that we still need to pass here: forma = reduxForm ({form: 'bla', validate: validateArticleDlg, onSubmit: function () {}}) (forma); then everything works. In general, API redux-form full r. - kidar2