mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
prevent 'do you want to leave'-alert when redirect occurs through paypal module.
This commit is contained in:
parent
3281043bc2
commit
6d8b6bf693
1 changed files with 25 additions and 0 deletions
|
@ -28,6 +28,24 @@ function onboardingCallback(authCode, sharedId) {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the PayPal modal will redirect the user a dirty form
|
||||
* provokes an alert if the user wants to leave the page. Since the user
|
||||
* needs to toggle the sandbox switch, we disable this dirty state with the
|
||||
* following workaround for checkboxes.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
const checkBoxOnClick = (event) => {
|
||||
const value = event.target.checked;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
setTimeout( () => {
|
||||
event.target.checked = value;
|
||||
},1
|
||||
);
|
||||
}
|
||||
|
||||
const sandboxSwitch = (element) => {
|
||||
|
||||
const toggleConnectButtons = (showProduction) => {
|
||||
|
@ -54,4 +72,11 @@ const sandboxSwitch = (element) => {
|
|||
if (sandboxSwitchElement) {
|
||||
sandboxSwitch(sandboxSwitchElement);
|
||||
}
|
||||
|
||||
document.querySelectorAll('#mainform input[type="checkbox"]').forEach(
|
||||
(checkbox) => {
|
||||
checkbox.addEventListener('click', checkBoxOnClick);
|
||||
}
|
||||
);
|
||||
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue