Changeset - ccc036d631c2
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 1 month ago 2024-05-09 04:10:10
ben@sturm.com.au
Fix JS error
1 file changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy/static/js/supporter-page.js
Show inline comments
...
 
@@ -15,53 +15,54 @@ var flipClass = function(elem, byeClass, hiClass) {
 
    classList.add(hiClass);
 
}
 

	
 
var buildAmountData = function(amountInput) {
 
    var amountData = {
 
        minAmount: parseFloat(amountInput.min),
 
        newAmount: parseFloat(amountInput.value),
 
    }
 
    if (amountInput.dataset.oldAmount !== undefined) {
 
        amountData.oldAmount = parseFloat(amountInput.dataset.oldAmount);
 
    }
 
    return amountData;
 
}
 

	
 
var supportTypeSelector = function(supportTypeHash) {
 
    return $(supportTypeHash + "Selector");
 
};
 

	
 
/* We've sometimes published links that say #renew instead of #renewal.
 
Rewrite that to work as intended. */
 
if (window.location.hash === "#renew") {
 
    window.location.hash = "#renewal";
 
}
 

	
 
var $formCorrectionNeeded = $('#form-correction-needed');
 

	
 
function init_sustainer_form_validation () {
 
    // Forms start in "invalid" form, with the errors shown, so that
 
    // non-Javascript users see the errors by default and know what they must
 
    // enter.  Now we hide those for JavaScript users:
 
    var $formCorrectionNeeded = $('#form-correction-needed');
 
    $formCorrectionNeeded.addClass('hidden');
 

	
 
    $('form.supporter-form').each(function(index, form) {
 
        var $amountInput = $('input[type=number]', form).first();
 
        var $amountError = $('.form-error', $amountInput.parents('.supporter-form-input'));
 

	
 
        $amountError.on(NEW_AMOUNT_EVENT, function(event, amountData) {
 
            var isValid = amountData.newAmount >= amountData.minAmount;
 
            if (amountData.oldAmount === undefined) {
 
                if (isValid) {
 
                    $amountError.addClass('hidden');
 
                } else {
 
                    flipClass($amountInput[0], 'valid', 'invalid');
 
                    $amountError.removeClass('hidden');
 
                }
 
            } else if (isValid) {
 
                flipClass($amountInput[0], 'invalid', 'valid');
 
                $amountError.fadeOut();
 
            } else if (amountData.oldAmount >= amountData.minAmount) {
 
                flipClass($amountInput[0], 'valid', 'invalid');
 
                $amountError.fadeIn();
 
            }
 
        });
 

	
0 comments (0 inline, 0 general)