Manually update store then trigger form submission synchronously
See original GitHub issueIt 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:
- Created 7 years ago
- Comments:17 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
http://stackoverflow.com/a/36070293/981177 <-- still not convinced
change
is synchronous…But yes your method could work as well!