Commit 2d0c7968 by Vedran Karacic Committed by Vedran Karačić

Fix Firefox autofill credit card bug.

parent de08a802
...@@ -132,12 +132,31 @@ define([ ...@@ -132,12 +132,31 @@ define([
appendCardValidationErrorMsg(event, cardExpiryMonthField, 'Card expired'); appendCardValidationErrorMsg(event, cardExpiryMonthField, 'Card expired');
} }
}, },
detectCreditCard = function() {
var cardNumber = $('#card-number-input').val().replace(/\s+/g, ''),
card,
iconPath = '/static/images/credit_cards/';
if (cardNumber.length > 12) {
card = CreditCardUtils.getCreditCardType(cardNumber);
if (typeof card !== 'undefined') {
$('.card-type-icon').attr(
'src',
iconPath + card.name + '.png'
);
$('input[name=card_type]').val(card.type);
} else {
$('.card-type-icon').attr('src', '');
$('input[name=card_type]').val('');
}
}
},
onReady = function() { onReady = function() {
var $paymentButtons = $('.payment-buttons'), var $paymentButtons = $('.payment-buttons'),
basketId = $paymentButtons.data('basket-id'), basketId = $paymentButtons.data('basket-id');
cardNumber,
iconPath = '/static/images/credit_cards/',
card;
$('#voucher_form_link').on('click', function(event) { $('#voucher_form_link').on('click', function(event) {
event.preventDefault(); event.preventDefault();
...@@ -150,28 +169,16 @@ define([ ...@@ -150,28 +169,16 @@ define([
}); });
$('#card-number-input').on('input', function() { $('#card-number-input').on('input', function() {
cardNumber = $('#card-number-input').val().replace(/\s+/g, ''); detectCreditCard();
if (cardNumber.length > 12) {
card = CreditCardUtils.getCreditCardType(cardNumber);
if (typeof card !== 'undefined') {
$('.card-type-icon').attr(
'src',
iconPath + card.name + '.png'
).removeClass('hidden');
$('input[name=card_type]').val(card.type);
} else {
$('.card-type-icon').attr('src', '').addClass('hidden');
$('input[name=card_type]').val('');
}
}
}); });
$('#payment-button').click(function(e) { $('#payment-button').click(function(e) {
_.each($('.help-block'), function(errorMsg) { _.each($('.help-block'), function(errorMsg) {
$(errorMsg).empty(); // Clear existing validation error messages. $(errorMsg).empty(); // Clear existing validation error messages.
}); });
if ($('#card-number-input').val()) {
detectCreditCard();
}
cardInfoValidation(e); cardInfoValidation(e);
cardHolderInfoValidation(e); cardHolderInfoValidation(e);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment