From c60e0eaed6e254e1ae25d7a067e874f39bee22fd Mon Sep 17 00:00:00 2001 From: Brendan Date: Fri, 25 Apr 2014 09:52:43 -0400 Subject: [PATCH] Fix for iOS 7's save credit card modal See https://github.com/GoodCloud/django-zebra/issues/36 - this is the fix for it that worked for me. --- zebra/static/zebra/card-form.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/zebra/static/zebra/card-form.js b/zebra/static/zebra/card-form.js index 139d0aa..2ab6a64 100644 --- a/zebra/static/zebra/card-form.js +++ b/zebra/static/zebra/card-form.js @@ -1,9 +1,27 @@ + $(function() { - $("#id_card_number").parents("form").submit(function() { - if ( $("#id_card_number").is(":visible")) { + var iOSCheck = false; + var cardField = $("#id_card_number"); + + if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { // This could be more elegant; should sniff iOS 7.x specifically + iOSCheck = true; + } + + if (iOSCheck == true) { + $("#id_card_number").attr('id','workaround-one'); // Rename ID. Nondescript name. + $('#workaround-one').attr('autocomplete','off'); // Turn off autocomplete + + $("#w1-label").after('
Credit Card
'); // Kill the label. Append the text, + $("#w1-label").remove(); // Then remove the label. That way the text in the label doesn't link to the CC field. + + cardField = $('#workaround-one'); // Redefine our credit card field so we can reference it below. + } + + cardField.parents("form").submit(function() { + if ( cardField.is(":visible") ) { var form = this; var card = { - number: $("#id_card_number").val(), + number: cardField.val(), expMonth: $("#id_card_expiry_month").val(), expYear: $("#id_card_expiry_year").val(), cvc: $("#id_card_cvv").val() @@ -11,12 +29,13 @@ $(function() { Stripe.createToken(card, function(status, response) { if (status === 200) { - // console.log(status, response); + //console.log(status, response); $("#credit-card-errors").hide(); $("#id_last_4_digits").val(response.card.last4); $("#id_stripe_token").val(response.id); form.submit(); - $("button[type=submit]").attr("disabled","disabled").html("Submitting..") + + $("button[type=submit]").attr("disabled","disabled").html("Submitting..") } else { $(".payment-errors").text(response.error.message); $("#user_submit").attr("disabled", false); @@ -27,7 +46,7 @@ $(function() { } - return true + return true; }); });