MediaWiki:MonthlyConvert.js: Difference between revisions

Content deleted Content added
No edit summary
add validation
Line 149:
}
return formattedAmount;
};
 
mc.getOtherAmount = function() {
var otherInput = document.getElementById('mc-other-amount-input'),
otherAmount = null;
 
// Check the "other" amount box
if ( otherInput.value !== '' ) {
otherAmount = otherInput.value;
otherAmount = otherAmount.replace(/[,.](\d)$/, '\:$10');
otherAmount = otherAmount.replace(/[,.](\d)(\d)$/, '\:$1$2');
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
}
 
otherAmount = parseFloat( otherAmount );
 
if ( isNaN( otherAmount ) ) {
return 0;
} else {
return otherAmount;
}
 
};
 
/**
* Check if selected amount is valid i.e. a positive number, between minimum and maximum.
* If not, show an error and return false.
*/
mc.validateOtherAmount = function() {
 
var amount = mc.getOtherAmount();
var minAmount = donationForm.minimums[ donationForm.currency ] || 1;
 
if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmount ) {
$('.mc-edit-amount').addClass('mc-haserror');
$('.mc-error-bigamount').hide();
$('.mc-error-smallamount').show();
return false;
} else if ( amount > donationForm.maxUSD * minAmount ) {
$('.mc-edit-amount').addClass('mc-haserror');
$('.mc-error-bigamount').show();
return false;
} else {
$('.mc-edit-amount').removeClass('mc-haserror');
$('.mc-error-smallamount, .mc-error-bigamount').hide();
return true;
}
 
};
 
Line 158 ⟶ 207:
return false;
}
 
$('.mc-currencycode').text( currency );
 
Line 179 ⟶ 228:
}
} );
 
$( '.mc-back' ).on( 'click keypress', function ( e ) {
if ( e.which === 13 || e.type === 'click' ) {
Line 187 ⟶ 237:
}
} );
 
$( '.mc-donate-monthly-button' ).on( 'click keypress', function ( e ) {
if ( e.which === 13 || e.type === 'click' ) {
mc.validateOtherAmount();
}
} );
 
});