diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index 39b5f95adb..f0f29d4d46 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -822,7 +822,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 } }; @@ -858,6 +862,24 @@ disableSubmit( thisForm ); } + /** + * 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. */