title: PayPal Express Checkout button with validation when button is clicked
body: <p>I am coding the new PayPal Express Checkout JavaScript button so when it is clicked, some validation is run and based on the validation, the button experience is continued or suppressed.</p>
  
  <p>This demo shows some validation but not exactly what I need. <a href="https://developer.paypal.com/demo/checkout/#/pattern/validation" rel="nofollow noreferrer">https://developer.paypal.com/demo/checkout/#/pattern/validation</a></p>
  
  <p>I have this test case you can try: <a href="https://jsfiddle.net/gardavis/51kvtjax" rel="nofollow noreferrer">https://jsfiddle.net/gardavis/51kvtjax</a> - this code uses PayPal's script: <a href="https://www.paypalobjects.com/api/checkout.js" rel="nofollow noreferrer">https://www.paypalobjects.com/api/checkout.js</a>.</p>
  
  <p>This is the part of the jsfiddle I am attempting to get working...</p>
  
  <pre><code>// Called when page displays
  validate: function(actions) {
      console.log("validate called");
      actions.disable(); // Allow for validation in onClick()
      paypalActions = actions; // Save for later enable()/disable() calls
  },
  
  // Called for every click on the PayPal button even if actions.disabled
  onClick: function() {
      console.log('onClick called');
      // Do validations and if OK, continue on to PayPal popup
      var zip = document.querySelector('#zipcode').value;
      var isValid = zip.length &gt;= 5;
      // Issue: fix to continue if valid, suppress popup if invalid
      if (isValid) {
          document.querySelector('#msg').style.display = 'none';
          paypalActions.enable();
          // TODO: Simulate click of PayPal button to display popup
      } else {
          document.querySelector('#msg').style.display = 'block';
          paypalActions.disable(); // Too late
      }
  },
  </code></pre>
  
  <p>The validate() is called once, basically when the page is loaded. That's too early to validate. The onClick() function is called when the button is clicked and a good place to do my validation but I don't have a way to continue if valid and display the error if not.</p>
  
  <p>The demo uses a checkbox event within the scope of the validate() function so it is able to enable/disable the PayPal popup (onClick() still works if disabled). The demo's onClick() simply shows/hides the error message.</p>
  
  <p>Does anyone know how to do validation within onClick()?</p>