prevent 'do you want to leave'-alert when redirect occurs through paypal module.

This commit is contained in:
David Remer 2020-09-24 12:50:35 +03:00
parent 3281043bc2
commit 6d8b6bf693

View file

@ -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);
}
);
})();