Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe Elements submit button stuck in disabled state. #39

Closed
stuffmatic opened this issue Mar 19, 2020 · 1 comment
Closed

Stripe Elements submit button stuck in disabled state. #39

stuffmatic opened this issue Mar 19, 2020 · 1 comment

Comments

@stuffmatic
Copy link
Contributor

The payment form submit button is created like this in the default _payment.html.erb template

<div class="form-buttons" data-hook="buttons">
  <%= submit_tag t('spree.save_and_continue'), class: 'continue button primary' %>
  <script>Spree.disableSaveOnClick();</script>
</div>

As far as I can tell, Spree.disableSaveOnClick() disables the submit button when the form is submitted, leaving it up to the response handler to re-enable it if the request fails. However, Stripe Elements sometimes seem to invoke the response handler immediately (probably based on cached form state), before Spree.disableSaveOnClick() disables the button, with the effect that the button remains disabled. This can be reproduced like this:

  1. Submit payment form without filling in any fields. This results in an error message and the submit button is re-enabled.
  2. Submit the empty form again.
  3. Fill in valid payment info, try to click the submit button and notice it's disabled.

I tried changing the code that re-enables the submit button in SolidusStripe.Elements.prototype.showError to this

setTimeout(function () {
    this.submitButton.removeAttr('disabled').removeClass('disabled');
}.bind(this), 10)

which seems to solve the problem. It's not very pretty though...

Any ideas about how to proceed with this? Should it be fixed in solidus_stripe?

@stuffmatic
Copy link
Contributor Author

Looks like I spoke too soon... Sorry about the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant