diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index 13371c0a8a..a10bb5a862 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -718,7 +718,11 @@ onError, style: frmPayPalVars.style, inputEvents: { - onChange: onCardFieldsChange + onChange: onCardFieldsChange, + // This is intentionally left blank, but it should not be deleted. onFocus is required for onBlur to work. + // eslint-disable-next-line no-empty + onFocus() {}, + onBlur: onCardFieldsBlur } }; @@ -749,6 +753,24 @@ } } + /** + * Handle card field blur events. + */ + async function onCardFieldsBlur() { + try { + const state = await cardFieldsInstance.getState(); + cardFieldsValid = state.isFormValid; + + if ( selectedMethod === 'card' ) { + if ( cardFieldsValid ) { + enableSubmit(); + } else { + disableSubmit( thisForm ); + } + } + } catch ( err ) {} // eslint-disable-line no-empty + } + /** * Render the card number / expiry / CVV fields into the method container. */