MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
add localizeErrors method, and put minimums here for now
add new validation method
Line 560:
var form = document.paypalcontribution; // we should really change this some day
if ( skipValidation || validateFormdonationForm.validate(form) ) {
 
if (typeof paymentSubMethod == 'undefined') {
Line 667:
form.utm_campaign.value = getQuerystring( 'utm_campaign' );
};
 
/**
* Validate the form.
* TODO: Clean up to be more like banners i.e. split out getAmount
*/
donationForm.validate = function() {
 
var amount = null;
var error = false;
var form = document.paypalcontribution;
var currency = document.paypalcontribution.currency_code.value;
var minAmount = donationForm.minimums[ currency ] || 1;
 
// Reset all errors
$('.lp-haserror').removeClass('lp-haserror');
$('.lp-error').hide();
 
// Get amount selection
for ( var i = 0; i < form.amount.length; i++ ) {
if ( form.amount[i].checked ) {
amount = form.amount[i].value;
}
}
 
if ( form.input_amount_other_box.value != "" ) {
var otherAmount = form.input_amount_other_box.value;
otherAmount = otherAmount.replace(/[,.](\d)$/, '\:$10');
otherAmount = otherAmount.replace(/[,.](\d)(\d)$/, '\:$1$2');
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
form.input_amount_other_box.value = otherAmount;
form.amountGiven.value = otherAmount;
amount = otherAmount;
}
 
if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmount ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-smallamount').show();
error = true;
} else if ( amount > 10000 * minAmount ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').show();
error = true;
} else {
$('.amount-options').removeClass('lp-haserror');
$('.lp-error-smallamount, .lp-error-bigamount').hide();
}
 
if ( form.opt_in ) {
if ( $("input[name='opt_in']:checked").val() === undefined ) {
$('#error-optin').show();
error = true;
} else {
$('#error-optin').hide();
form.variant.value = 'emailExplain';
}
}
return !error;
}
 
donationForm.toggleMonthly = function(monthly) {