woocommerce-paypal-payments/modules/ppcp-wc-gateway/resources/js/gateway-settings.js
Danae Millan 587d3eef53 Disable the vaulting checkbox only when vaulting isn't in the scope
Now, as long as vaulting is in the PayPal account's scope, the checkbox would always be enabled. Independently from the Pay Later settings.
2021-11-20 12:51:11 -03:00

38 lines
1.3 KiB
JavaScript

;document.addEventListener(
'DOMContentLoaded',
() => {
const payLaterMessagingCheckboxes = document.querySelectorAll(
"#ppcp-message_enabled, #ppcp-message_cart_enabled, #ppcp-message_product_enabled"
)
const vaultingCheckboxes = document.querySelectorAll(
"#ppcp-vault_enabled"
)
const disabledCheckboxes = document.querySelectorAll(
'.ppc-disabled-checkbox'
)
function atLeastOneChecked(checkboxesNodeList) {
return Array.prototype.slice.call(checkboxesNodeList).filter(node => !node.disabled && node.checked).length > 0
}
function disableAll(nodeList){
nodeList.forEach(node => node.setAttribute('disabled', 'true'))
}
function enableAll(nodeList){
nodeList.forEach(node => node.removeAttribute('disabled'))
}
function updateCheckboxes() {
disableAll( disabledCheckboxes );
atLeastOneChecked(vaultingCheckboxes) ? disableAll(payLaterMessagingCheckboxes) : enableAll(payLaterMessagingCheckboxes)
}
updateCheckboxes()
payLaterMessagingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes))
vaultingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes));
}
);