K
K
kidar22018-02-10 09:40:03
JavaScript
kidar2, 2018-02-10 09:40:03

How to programmatically submit a redux form?

There is this form:

<form ref="myform" onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
...
</form>

Tried different ways:
1. this.props.dispatch(submit('CreateArticleDialog')); => error:
You must either pass handleSubmit() an onSubmit function or pass onSubmit as a pro
2. this.refs.myform.submit(); => make a post request and update the entire page
3. this.props.handleSubmit(this.handleFormSubmit.bind(this)); => nothing happens

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kidar2, 2018-02-10
@kidar2

It turned out to do this:

onSomeClick() {
    const {store} = this.context;
    const state = store.getState();
    let data = getFormValues('form-id')(state);
    this.handleFormSubmit(data);
  }

In order for the store to be in the context, it is necessary to register the react component:
static contextTypes = {store: PropTypes.object};

B
BugsCreator, 2018-02-10
@BugsCreator

Try

<form ref="myform" onSubmit={() => this.handleSubmit}>
...
</form>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question