Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
add methods to show and hide errors
Browse files Browse the repository at this point in the history
  • Loading branch information
WMDE-Fisch committed Dec 28, 2015
1 parent b2051cf commit fd9b41c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions js/common-banner.js
Expand Up @@ -251,17 +251,19 @@ function validateForm() {

// Check amount is at least the minimum
if ( amount < 1 || error ) {
alert( amountTooLowMessage );
showAmountError( amountTooLowMessage );
return false;
} else if ( amount > 99999 ) {
alert( amountTooHighMessage );
showAmountError( amountTooHighMessage );
return false;
} else {
hideAmountError();
}
return amount;
}

function showAmountError() {
$( '#WMDE_Banner-amounts-error-text' ).show();
function showAmountError( text ) {
$( '#WMDE_Banner-amounts-error-text' ).text( text ).show();
$( '#WMDE_Banner-amounts' ).addClass( 'fieldset-error' );
}

Expand All @@ -270,8 +272,8 @@ function hideAmountError() {
$( '#WMDE_Banner-amounts' ).removeClass( 'fieldset-error' );
}

function showFrequencyError() {
$( '#WMDE_Banner-frequency-error-text' ).show();
function showFrequencyError( text ) {
$( '#WMDE_Banner-frequency-error-text' ).text( text ).show();
$( '#WMDE_Banner-frequency' ).addClass( 'fieldset-error' );
}

Expand All @@ -289,7 +291,7 @@ function validateAndSetPeriod() {
var form = document.donationForm;
if ( $( '#interval_multiple' ).is( ':checked' ) ) {
if ( $( 'input[name=interval]:checked', form ).length !== 1 ) {
alert( noIntervalSelectedMessage );
showFrequencyError( noIntervalSelectedMessage );
return false;
} else {
$( '#intervalType' ).val( '1' );
Expand All @@ -299,9 +301,10 @@ function validateAndSetPeriod() {
$( '#periode' ).val( '0' );
$( '#intervalType' ).val( '0' );
} else {
alert( noIntervalSelectedMessage );
showFrequencyError( noIntervalSelectedMessage );
return false;
}
hideFrequencyError();
return true;
}

Expand Down

0 comments on commit fd9b41c

Please sign in to comment.