Template:Validation.js: Difference between revisions

From Donate
Jump to navigation Jump to search
Content deleted Content added
Tag: Replaced
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
/* Merged to [[MediaWiki:DonationForm.js]] */
<html>
<script>
function validateForm(form){
var amount = null;
var minimums = {
/* From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php */
'ADF' : 5.65,
'ADP' : 143,
'AED' : 3.67,
'AFA' : 73,
'AFN' : 73,
'ALL' : 109,
'AMD' : 477,
'ANG' : 1.79,
'AOA' : 278,
'AON' : 278,
'ATS' : 12,
'AUD' : 1.39,
'AWG' : 1.78,
'AZM' : 8486,
'AZN' : 1.7,
'BAM' : 1.69,
'BBD' : 2,
'BDT' : 83,
'BEF' : 35,
'BGL' : 1.69,
'BGN' : 1.69,
'BHD' : 0.38,
'BIF' : 1748,
'BMD' : 1,
'BND' : 1.38,
'BOB' : 6.8,
'BRL' : 4.15,
'BSD' : 1,
'BTN' : 72,
'BWP' : 11,
'BYR' : 21035,
'BZD' : 1.98,
'CAD' : 1.32,
'CDF' : 1573,
'CHF' : 0.98,
'CNY' : 6.83,
'CRC' : 572,
'CUC' : 1,
'CUP' : 25,
'CVE' : 95,
'CYP' : 0.51,
'CZK' : 22,
'DEM' : 1.69,
'DJF' : 178,
'DKK' : 6.42,
'DOP' : 50,
'DZD' : 118,
'ECS' : 24094,
'EEK' : 13,
'EGP' : 18,
'ESP' : 143,
'ETB' : 27,
'EUR' : 0.87,
'FIM' : 5.12,
'FJD' : 2.1,
'FKP' : 0.78,
'FRF' : 5.65,
'GBP' : 0.78,
'GEL' : 2.52,
'GHC' : 47467,
'GHS' : 4.75,
'GIP' : 0.78,
'GMD' : 48,
'GNF' : 8983,
'GRD' : 294,
'GTQ' : 7.5,
'GYD' : 204,
'HKD' : 7.85,
'HNL' : 24,
'HRK' : 6.4,
'HTG' : 68,
'HUF' : 282,
'IDR' : 14966,
'IEP' : 0.68,
'ILS' : 3.61,
'INR' : 72,
'IQD' : 1178,
'IRR' : 42000,
'ISK' : 109,
'ITL' : 1669,
'JMD' : 136,
'JOD' : 0.71,
'JPY' : 112,
'KES' : 100,
'KGS' : 69,
'KHR' : 4025,
'KMF' : 424,
'KPW' : 135,
'KRW' : 1120,
'KWD' : 0.31,
'KYD' : 0.84,
'KZT' : 369,
'LAK' : 8393,
'LBP' : 1508,
'LKR' : 162,
'LRD' : 154,
'LSL' : 15,
'LTL' : 2.98,
'LUF' : 35,
'LVL' : 0.61,
'LYD' : 1.37,
'MAD' : 9.39,
'MDL' : 17,
'MGA' : 3311,
'MGF' : 9150,
'MKD' : 53,
'MMK' : 1529,
'MNT' : 2460,
'MOP' : 8.08,
'MRO' : 357,
'MTL' : 0.37,
'MUR' : 33,
'MVR' : 15,
'MWK' : 717,
'MYR' : 4.15,
'MZM' : 59754,
'MZN' : 60,
'NAD' : 15,
'NGN' : 359,
'NIO' : 32,
'NLG' : 1.9,
'NOK' : 8.4,
'NPR' : 114,
'NZD' : 1.52,
'OMR' : 0.39,
'PAB' : 1,
'PEN' : 3.3,
'PGK' : 3.26,
'PHP' : 54,
'PKR' : 123,
'PLN' : 3.72,
'PTE' : 173,
'PYG' : 5763,
'QAR' : 3.57,
'ROL' : 39889,
'RON' : 3.99,
'RSD' : 101,
'RUB' : 68,
'RWF' : 862,
'SAR' : 3.75,
'SBD' : 7.6,
'SCR' : 13,
'SDD' : 1795,
'SDG' : 18,
'SDP' : 2261,
'SEK' : 9.08,
'SGD' : 1.38,
'SHP' : 0.78,
'SIT' : 207,
'SKK' : 26,
'SLL' : 8430,
'SOS' : 542,
'SRD' : 7.41,
'SRG' : 7408,
'STD' : 21070,
'SVC' : 8.75,
'SYP' : 215,
'SZL' : 15,
'THB' : 33,
'TJS' : 9.36,
'TMM' : 17050,
'TMT' : 3.41,
'TND' : 2.76,
'TOP' : 2.29,
'TRL' : 6629223,
'TRY' : 6.63,
'TTD' : 6.64,
'TWD' : 31,
'TZS' : 2281,
'UAH' : 28,
'UGX' : 3749,
'USD' : 1,
'UZS' : 7780,
'VEB' : 6050841136,
'VEF' : 6050841,
'VND' : 23150,
'VUV' : 111,
'WST' : 2.64,
'XAF' : 565,
'XCD' : 2.7,
'XOF' : 565,
'XPF' : 103,
'YER' : 250,
'YUN' : 101,
'ZAR' : 15,
'ZMK' : 5176,
'ZWD' : 373,
/* Astropay currencies have higher minimums - 1.50 USD */
'ARS' : 58.5,
'BRL' : 6.23,
'CLP' : 1035,
'COP' : 4640,
'MXN' : 28.5
};

var error = true;

// 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;
}

// Check amount is a real number
error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
// Check amount is at least the minimum
var currency = form.currency_code.value;
if ( typeof( minimums[currency] ) == 'undefined' ) {
minimums[currency] = 1;
}
if ( error ) {
alert( "</html>{{int:donate_interface-amount-error}}<html>" );
} else if ( amount < minimums[currency] ) {
$( "#input_amount_other_box" ).val( '' );
alert( "</html>{{int:donate_interface-smallamount-error}}<html>".replace('$1', (minimums[currency] + ' ' + currency) ) );
error = true;
}
if ( amount > 10000*minimums[currency]) {
$( "#input_amount_other_box" ).val( '' );
errorMessageLarge = "</html>{{int:Donate interface-bigamount-error}}<html>";
errorMessageLarge = errorMessageLarge.replace('$1',10000*minimums[currency]);
errorMessageLarge = errorMessageLarge.replace('$2',currency);
errorMessageLarge = errorMessageLarge.replace('$3','benefactors@wikimedia.org');
alert(errorMessageLarge);
error = true;
}

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;
}
</script>
</html>

Latest revision as of 18:03, 28 March 2019

/* Merged to [[MediaWiki:DonationForm.js]] */