jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/365648 )

Change subject: Leave form disabled while redirecting to PayPal EC
......................................................................


Leave form disabled while redirecting to PayPal EC

And only auto-submit if there are no errors from the server-side
validation.

Bug: T167923
Change-Id: I92bf95118eb2f97be5045596c7d3ea9bcba39250
---
M modules/js/ext.donationInterface.forms.js
M modules/js/ext.donationInterface.validation.js
M paypal_gateway/express_checkout/forms/js/paypal.js
3 files changed, 19 insertions(+), 3 deletions(-)

Approvals:
  Mepps: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/js/ext.donationInterface.forms.js 
b/modules/js/ext.donationInterface.forms.js
index dd0a103..5b72dd3 100644
--- a/modules/js/ext.donationInterface.forms.js
+++ b/modules/js/ext.donationInterface.forms.js
@@ -31,7 +31,7 @@
        /**
         * Call the generic donation API and handle errors or execute a callback
         *
-        * @param {function()} successCallback will be called with response's 
'result' property
+        * @param {function(result)} successCallback will be called with 
response's 'result' property
         */
        function callDonateApi( successCallback ) {
                di.forms.disable();
diff --git a/modules/js/ext.donationInterface.validation.js 
b/modules/js/ext.donationInterface.validation.js
index de472dd..aea1f0e 100644
--- a/modules/js/ext.donationInterface.validation.js
+++ b/modules/js/ext.donationInterface.validation.js
@@ -34,6 +34,16 @@
                }
        }
 
+       /**
+        * Are any errors currently showing, from either server-side or
+        * client-side validation?
+        *
+        * @return {boolean}
+        */
+       function hasErrors() {
+               return $( '.errorMsg' ).length > 0;
+       }
+
        di.validation = {
                validate: function () {
                        // This funkiness is to make sure we run all the 
validations and
@@ -51,7 +61,8 @@
                // FIXME: Move global scope functions here
                validateAmount: window.validateAmount,
                validatePersonal: window.validate_personal,
-               showErrors: showErrors
+               showErrors: showErrors,
+               hasErrors: hasErrors
        };
 
        // Set up email error detection and correction
diff --git a/paypal_gateway/express_checkout/forms/js/paypal.js 
b/paypal_gateway/express_checkout/forms/js/paypal.js
index 9f41454..b05dcc2 100644
--- a/paypal_gateway/express_checkout/forms/js/paypal.js
+++ b/paypal_gateway/express_checkout/forms/js/paypal.js
@@ -2,11 +2,16 @@
        var di = mw.donationInterface;
 
        function redirect( result ) {
+               // We don't actually want to enable the form on redirect or in 
the
+               // complete phase of callDonateApi, so we override enable here.
+               di.forms.enable = function(){};
                top.location.href = result.formaction;
        }
 
        di.forms.submit = function () {
                di.forms.callDonateApi( redirect );
        };
-       di.forms.submit();
+       if ( !di.validation.hasErrors() ) {
+               di.forms.submit();
+       }
 } )( jQuery, mediaWiki );

-- 
To view, visit https://gerrit.wikimedia.org/r/365648
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I92bf95118eb2f97be5045596c7d3ea9bcba39250
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Mepps <me...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to