javascript - Pop up djstripe payments modal without button click -
since have 1 djstripe subscription plan, i'm trying djstripe payments/subscribe page pop payments modal without click. javascript works click of button this:
$(function() { $('body').on("click", '.djstripe-subscribe button[type=submit]', function(e) { e.preventdefault(); // retrieve current $(".djstripe-subscribe") var $form = $(e.target).parents('form'), token = function(res) { $form.find("input[name=stripe_token]").val(res.id); $("button[type=submit]").attr("disabled", "true"); $('#in-progress').modal({"keyboard": false}) $('.progress-bar').animate({width:'+=100%'}, 2000); $form.trigger("submit"); }; stripecheckout.open({ key: "{{ stripe_public_key }}", name: 'payment method', panellabel: 'add payment method', token: token }); return false; }); {% if plan_list|length > 1 %} $('.djstripe-change-plan').click(function(e){ $("button[type=submit]").attr("disabled", "true"); $('#in-progress').modal({"keyboard": false}) $('.progress-bar').animate({width:'+=100%'}, 2000); var $form = $(this); $form.trigger("submit"); }); {% endif %} });
i've been able modal pop removing wrapper function , putting script in document ready function, this:
$(document).ready(function(e) { // retrieve current $(".djstripe-subscribe") var $form = $(e.target).parents('form'), token = function(res) { $form.find("input[name=stripe_token]").val(res.id); $("button[type=submit]").attr("disabled", "true"); $('#in-progress').modal({"keyboard": false}) $('.progress-bar').animate({width:'+=100%'}, 2000); $form.trigger("submit"); }; stripecheckout.open({ key: "{{ stripe_public_key }}", name: 'payment method', panellabel: 'add payment method', token: token }); return false; }); {% if plan_list|length > 1 %} $('.djstripe-change-plan').click(function(e){ $("button[type=submit]").attr("disabled", "true"); $('#in-progress').modal({"keyboard": false}) $('.progress-bar').animate({width:'+=100%'}, 2000); var $form = $(this); $form.trigger("submit"); }); {% endif %}
however, eliminates .djstripe-subscribe button[type=submit] selector, causes errors e.preventdefault() unless remove shown in code snippet, , makes "server update" comes after payment method submitted crank eternally no results. how can modal pop , update successfully?
one way using jquery's .click() method (https://api.jquery.com/click/) on first version of code, 'click' element on page load?
Comments
Post a Comment