webdna / commerce-braintree

Braintree gateway for Craft Commerce
Other
2 stars 11 forks source link

JQuery submit no longer automatically submitting the form #22

Closed AMHVerse closed 4 years ago

AMHVerse commented 4 years ago

We placed the code into our payment form and doesn't get to the thank you page in Chrome.

Looked into it and In vendor/kuriousagency/commerce-braintree/src/assetbundles/dropinui/dist/js/DropinUi.js on line 157 It uses jQuery to submit the form, this doesn't always work.

Changing this to $form[0].submit(); works for us

wagood commented 4 years ago

same issue

2019-12-12_11-11-20

panosdigital commented 4 years ago

Same here! There seems to a confusion when there more than two forms in the same page. The plugin seems to try to automatically submit the wrong form.

karensg commented 4 years ago

Yup, would be great to get a fix out for this issue

samuelbirch commented 4 years ago

i've changed it to use $form.trigger('submit'), i've tested with multiple forms on the page and its working fine for me. Please let me know if you're still having issues.

fixed in 2.3.0

panosdigital commented 4 years ago

@samuelbirch I'm sorry but I'm still having problems. On my code (and the demo templates of Craft), the $form variable is an array containing one element. The form element in that array is the correct one but calling $form.trigger("submit"); doesn't seem to trigger the submission whereas $form[0].submit(); does.

samuelbirch commented 4 years ago

what version of jQuery are you using?

panosdigital commented 4 years ago

@samuelbirch I'm using jQuery 3.4.1

wagood commented 4 years ago

Craft demo shop. Jquery 2.1.4 2019-12-16_10-25-36

samuelbirch commented 4 years ago

If you are using the default templates it looks like this be of javascript code is blocking the form from submitting:

` $('#paymentForm').on('submit', function (ev) { $form = $(this);

        if ($form.data('processing')) {
            ev.preventDefault();

            return false;
        }

        $form.data('processing', true);
    });`

removing this will make it work.

the reason being, this snippet of code only allows the form to be submitted once, but in the case of braintree we submit the form first and block it in order to get the nonce and add it to the hidden input, we then unblock the form and submit it again, this time allowing it to post to the controller.