mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
hide disabled credit cards in the logo selection
This commit is contained in:
parent
82f4d1e0af
commit
25c87a8da8
1 changed files with 48 additions and 10 deletions
|
@ -59,17 +59,55 @@ const groupToggleSelect = (selector, group) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const disableOptions = (sourceSelector, targetSelector) => {
|
||||||
|
|
||||||
|
const source = jQuery(sourceSelector);
|
||||||
|
const target = document.querySelector(targetSelector);
|
||||||
|
if (! target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const allOptions = Array.from(document.querySelectorAll('select[name="ppcp[disable_cards][]"] option'));
|
||||||
|
const replace = () => {
|
||||||
|
const validOptions = allOptions.filter(
|
||||||
|
(option) => {
|
||||||
|
|
||||||
|
return ! option.selected
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const selectedValidOptions = validOptions.map(
|
||||||
|
(option) => {
|
||||||
|
option = option.cloneNode(true);
|
||||||
|
option.selected = target.querySelector('option[value="' + option.value + '"]') && target.querySelector('option[value="' + option.value + '"]').selected;
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
target.innerHTML = '';
|
||||||
|
selectedValidOptions.forEach(
|
||||||
|
(option) => {
|
||||||
|
target.append(option);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
source.on('change',replace);
|
||||||
|
replace();
|
||||||
|
}
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
document.querySelector('#field-toggle_manual_input').addEventListener(
|
const manualInputToggle = document.querySelector('#field-toggle_manual_input');
|
||||||
|
if (manualInputToggle) {
|
||||||
|
manualInputToggle.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
(event) => {
|
(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.querySelector('#field-toggle_manual_input').style.display = 'none';
|
document.querySelector('#field-toggle_manual_input').classList.toggle('show');
|
||||||
document.querySelector('#field-merchant_id').style.display = 'table-row';
|
document.querySelector('#field-merchant_id').classList.toggle('show');
|
||||||
document.querySelector('#field-client_id').style.display = 'table-row';
|
document.querySelector('#field-client_id').classList.toggle('show');
|
||||||
document.querySelector('#field-client_secret').style.display = 'table-row';
|
document.querySelector('#field-client_secret').classList.toggle('show');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
disableOptions('select[name="ppcp[disable_cards][]"]', 'select[name="ppcp[card_icons][]"]');
|
||||||
|
|
||||||
groupToggle(
|
groupToggle(
|
||||||
'#ppcp-button_enabled',
|
'#ppcp-button_enabled',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue