MediaWiki:MonthlyConvert.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
add validation |
||
Line 149: | Line 149: | ||
} |
} |
||
return formattedAmount; |
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: | Line 207: | ||
return false; |
return false; |
||
} |
} |
||
⚫ | |||
$('.mc-currencycode').text( currency ); |
$('.mc-currencycode').text( currency ); |
||
Line 179: | Line 228: | ||
} |
} |
||
} ); |
} ); |
||
$( '.mc-back' ).on( 'click keypress', function ( e ) { |
$( '.mc-back' ).on( 'click keypress', function ( e ) { |
||
if ( e.which === 13 || e.type === 'click' ) { |
if ( e.which === 13 || e.type === 'click' ) { |
||
Line 187: | Line 237: | ||
} |
} |
||
} ); |
} ); |
||
$( '.mc-donate-monthly-button' ).on( 'click keypress', function ( e ) { |
|||
if ( e.which === 13 || e.type === 'click' ) { |
|||
mc.validateOtherAmount(); |
|||
} |
|||
} ); |
|||
}); |
}); |