Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion paypal/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'onFocus'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

onBlur: onCardFieldsBlur
}
};

Expand Down Expand Up @@ -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.
*/
Expand Down
Loading