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.

Manually update store then trigger form submission synchronously

See original GitHub issue

It would be great if there was a way to add/update a value manually on the form, then submit the form right after. For instance, in a form that tokenizes a credit card token for Stripe, I’d like to handle the Stripe response by setting the token ID in the callback then triggering form submit. Something like this:

stripeResponseHandler = (status, response, values) => {
    if(response.error) {
      // Stuff
      this.setState({
        error: response.error.message
      })
    } else { // Token created
      this.clearError()
      // These next two lines would need to happen syncronously, the submit would need to wait for the change.
      this.props.change('customer.stripe_token', response.id)
      this.onSubmit() // Whatever function I'd normally pass to the form's handleSubmit prop
    }
  }

This is pretty standard in regular forms, and it may very well be possible with redux-form, but I’ve looked through similar issues and don’t see anything that would work.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
charlesrochaticommented, Mar 3, 2017

Didn’t know about this: "setState() does not immediately mutate this.state but creates a pending state transition. … "

That’s why they’re appending the json directly.

1reaction
TrevorHinesleycommented, Mar 3, 2017

http://stackoverflow.com/a/36070293/981177 <-- still not convinced change is synchronous…

But yes your method could work as well!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Submit form after calling e.preventDefault() - Stack Overflow
The simplest solution is just to not call e.preventDefault() unless validation actually fails. Move that line inside the inner if statement, and remove...
Read more >
Submit data for a form | Forms API - HubSpot API
Send form submission data to HubSpot. This endpoint supports cross-origin AJAX (CORS) requests, letting you submit data directly using ...
Read more >
Remote Submit Example - Redux Form
This example demonstrates how a form may be submitted by dispatching a SUBMIT action from an unrelated component or middleware. The "Submit" button...
Read more >
Schema reference for trigger and action types - Azure Logic ...
Schema reference guide for Workflow Definition Language trigger and action types in Azure Logic Apps.
Read more >
DynamoDB Streams and AWS Lambda triggers
For a high velocity stream in particular, it is better to trigger an asynchronous post-processing step function workflows than synchronous long running ...
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