Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/287139
Change subject: WIP no more alert() for API errors ...................................................................... WIP no more alert() for API errors wow, we really were looping across and calling alert() multiple times! Change-Id: I33ea610496bd6db25d3cae4cf4526d3717dccc71 --- M adyen_gateway/forms/js/adyen.js M gateway_forms/rapidhtml/RapidHtmlResources.php M globalcollect_gateway/forms/js/gc.js M modules/js/ext.donationInterface.validation.js 4 files changed, 30 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/39/287139/1 diff --git a/adyen_gateway/forms/js/adyen.js b/adyen_gateway/forms/js/adyen.js index e23bb5a..d9486df 100644 --- a/adyen_gateway/forms/js/adyen.js +++ b/adyen_gateway/forms/js/adyen.js @@ -53,10 +53,8 @@ $( '#paymentContinue' ).show(); // Show continue button in 2nd section } else if ( typeof data.result !== 'undefined' ) { if ( data.result.errors ) { - $.each( data.result.errors, function ( index, value ) { - alert( value ); // Show them the error - $( '#paymentContinue' ).show(); // Show continue button in 2nd section - } ); + mw.donationInterface.validation.setErrors( data.result.errors ); + $( '#paymentContinue' ).show(); // Show continue button in 2nd section } else if ( data.result.formaction && data.result.gateway_params ) { $payment = $( '#payment-form' ); diff --git a/gateway_forms/rapidhtml/RapidHtmlResources.php b/gateway_forms/rapidhtml/RapidHtmlResources.php index ed142c6..c2e260f 100644 --- a/gateway_forms/rapidhtml/RapidHtmlResources.php +++ b/gateway_forms/rapidhtml/RapidHtmlResources.php @@ -132,7 +132,7 @@ 'js/gc.cc.js' ), 'dependencies' => array( - 'di.form.core.validate', + 'ext.donationInterface.validation', 'mediawiki.Uri' ), 'localBasePath' => __DIR__ . '/../../globalcollect_gateway/forms', diff --git a/globalcollect_gateway/forms/js/gc.js b/globalcollect_gateway/forms/js/gc.js index 61e8451..ad424bc 100644 --- a/globalcollect_gateway/forms/js/gc.js +++ b/globalcollect_gateway/forms/js/gc.js @@ -78,10 +78,8 @@ } else if ( data.result !== undefined ) { if ( data.result.errors ) { $( '#payment' ).empty(); // Hide spinner - $.each( data.result.errors, function ( index, value ) { - alert( value ); // Show them the error - $( '#paymentContinue' ).show(); // Show continue button in 2nd section - } ); + mediaWiki.donationInterface.validation.setErrors( data.result.errors ); + $( '#paymentContinue' ).show(); // Show continue button in 2nd section } else if ( data.result.formaction || data.result.testform ) { mediaWiki.generatePaymentForm( data ); } diff --git a/modules/js/ext.donationInterface.validation.js b/modules/js/ext.donationInterface.validation.js index c9242b6..b3de70f 100644 --- a/modules/js/ext.donationInterface.validation.js +++ b/modules/js/ext.donationInterface.validation.js @@ -6,8 +6,32 @@ ( function ( $, mw ) { var di = mw.donationInterface = {}; + function setErrors ( errors ) { + var generalErrors = []; + + $.each( errors, function ( field, message ) { + var $input = $( '#' + field ); + + if ( $input.length > 0 ) { + $input.addClass( 'errorHighlight' ); + $( '#' + field + 'Msg' ) + .removeClass( 'errorMsgHide' ) + .addClass( 'errorMsg' ) + .text( message ); + } else { + generalErrors.push( message ); + } + } ); + if ( generalErrors.length > 0 ) { + $( '#topError' ).html( + generalErrors.join( '<br/>' ) + ); + } + } + di.validation = { validateAmount: window.validateAmount, - validatePersonal: window.validate_personal + validatePersonal: window.validate_personal, + setErrors: setErrors }; } )( jQuery, mediaWiki ); -- To view, visit https://gerrit.wikimedia.org/r/287139 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I33ea610496bd6db25d3cae4cf4526d3717dccc71 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits