I guess my question is easy but I can not figure it out even searching for days.
There is my practical situation:
I have a form and would like to wait for the return of a stripe asynchronous function before submitting it to my backend as I need the response of the stripe API. I am then using the onsubmit="return validate_form();">
tag in order to manage that by myself in a javascript function.
<form action="/" method="get" id="test" onsubmit="return validate_test_form();">
<button type="submit" id="iban-test" data-secret="">
TEST
</button>
</form>
function validate_test_form() {
var stripe_result = stripe.confirmCardSetup(clientSecret)
if (stripe_result.error) {
// do things
} else {
// do other things
}
return true;
}
As a normal behavior, the form is submitted without waiting for the stripe response as the stripe function is asynchronous and the default validate_test_form function return is true. I am aware of async/await/promise concepts but don't see how I can use them to wait (block UI, with a spinner or other) for the response of stripe as a synchronous behavior.
I imagine this situation must be current and it must be lots way to perform what I am looking for. In either way, could you tell me what are the best practices in this situation.
Thanks a lot for your time.
event.preventDefault(), and then manually submitting the form yourself, once the asynchronous operation is completed.event.preventDefault()like this:<form action="/" method="get" id="test" onsubmit="event.preventDefault(); validate_test_form();">, it works. Thanks