question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SET_SUBMIT_SUCCEEDED called from empty onSubmit and after stopSubmit with errors

See original GitHub issue

I’m not returning a Promise from my onSubmit, instead dispatching an action to be later picked up in a saga.

The saga calls, startSubmit('formName'), and then at some point later calling stopSubmit('formName', errors) (or just stopSubmit('formName') if everything was ok).

In the case of a failure, the errors are being properly picked up and applied to the form, however, I’m seeing the @@redux-form/SET_SUBMIT_SUCCEEDED action coming through as well, which results in an inconsistent form state. The submit failed, but @@redux-form/SET_SUBMIT_SUCCEEDED is setting submitSucceeded to true even though I signalled a failed submission.

I’m trying to signal a failure, but the action sequence I’m getting is,

screen shot 2017-01-26 at 12 04 25

What’s more, I get the @@redux-form/SET_SUBMIT_SUCCEEDED action creeping in even if I do nothing at all in onSubmit, i.e. with an empty onSubmit function that does nothing and doesn’t even return a Promise I see the following action,

screen shot 2017-01-26 at 13 02 52

In terms of correctness, correct me if I’m wrong, but I feel like this action shouldn’t be being called after an empty onSubmit that doesn’t return a Promise. In that case shouldn’t nothing have happened? A Promise wasn’t returned, and startSubmit() wasn’t called so why is Redux Form flipping submitSucceeded to true?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:7
  • Comments:41 (8 by maintainers)

github_iconTop GitHub Comments

14reactions
erikrascommented, Apr 15, 2017

Proposal

A new function, like handleSubmit, called dispatchSubmit, that you use like this:

<form onSubmit={this.props.dispatchSubmit}>
  ...
</form>

It will check that sync validation and async validation all passes, and if and only if the form is valid, it will dispatch an action that looks something like:

{
  type: '@@redux-form/DISPATCH_SUBMIT', // 'SUBMIT' is taken already... 😕
  payload: { 
    // all your form values
  }
}

The redux-form reducer will ignore this action entirely. It will be up to all your fancy async middlewares to dispatch startSubmit(), stopSubmit(), etc. to update the form’s submitting state manually.

Would that satisfy everyone’s needs?

7reactions
ecnaidarcommented, Apr 6, 2018

@erikras This looks interesting, though still feels a lot like hack and adds complexity. If there is still interest, I might get a PR going for the dispatchSubmit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onsubmit method doesn't stop submit - Stack Overflow
My idea was to put some mandatory fields and, in order to achieve that, I was using the onsubmit method inside a form...
Read more >
A higher order component decorator for forms using Redux ...
stopSubmit (form, errors); function redux-form.submit (form); function redux-form.touch (form) ... newValue)); // call post-blur callback if (_reduxForm.
Read more >
onsubmit Event - W3Schools
Execute a JavaScript when a form is submitted: <form onsubmit="myFunction()"> Enter name: <input type="text"> <input type="submit"> </form>.
Read more >
useForm - handleSubmit - React Hook Form
This function will receive the form data if form validation is successful. Props. Name, Type, Description. SubmitHandler, (data: Object, e?: Event) => void...
Read more >
onSubmit client script to prevent form submission - ServiceNow
I have an onSubmit catalog client script to prevent submission of a record producer if the user has not checked a box on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found