From 861034855ea2752e3603f5c324f0457a7d72e94a Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Wed, 11 Sep 2024 00:44:32 +0200 Subject: [PATCH] Make sure you can't trigger lookup when a different payment gateway is selected --- .../resources/js/helpers/emailSubmissionManager.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-axo-block/resources/js/helpers/emailSubmissionManager.js b/modules/ppcp-axo-block/resources/js/helpers/emailSubmissionManager.js index 3d0724f75..d8f5bd5c2 100644 --- a/modules/ppcp-axo-block/resources/js/helpers/emailSubmissionManager.js +++ b/modules/ppcp-axo-block/resources/js/helpers/emailSubmissionManager.js @@ -11,6 +11,7 @@ let submitButtonReference = { unsubscribe: null, }; let isLoading = false; +let keydownHandler = null; const getEmailInput = () => { if ( ! emailInput ) { @@ -88,8 +89,9 @@ export const setupEmailFunctionality = ( onEmailSubmit ) => { } }; - const keydownHandler = ( event ) => { - if ( event.key === 'Enter' ) { + keydownHandler = ( event ) => { + const isAxoActive = wp.data.select( STORE_NAME ).getIsAxoActive(); + if ( event.key === 'Enter' && isAxoActive ) { event.preventDefault(); handleEmailSubmit(); } @@ -137,8 +139,8 @@ export const setupEmailFunctionality = ( onEmailSubmit ) => { export const removeEmailFunctionality = () => { const input = getEmailInput(); - if ( input ) { - input.removeEventListener( 'keydown', input.onkeydown ); + if ( input && keydownHandler ) { + input.removeEventListener( 'keydown', keydownHandler ); } if ( submitButtonReference.root ) { @@ -156,6 +158,7 @@ export const removeEmailFunctionality = () => { ); } submitButtonReference = { container: null, root: null, unsubscribe: null }; + keydownHandler = null; }; export const isEmailFunctionalitySetup = () => {