refactor tabs script

This commit is contained in:
Анатолий Богомолов 2024-03-07 16:32:16 +10:00
parent 5f89b37983
commit 66fe246f5b
1 changed files with 14 additions and 15 deletions

View File

@ -5,31 +5,30 @@ tabs_lists.forEach((tabs_list) => {
tabs = [...tabs, ...tabs_list.querySelectorAll('[role="tab"]')]; tabs = [...tabs, ...tabs_list.querySelectorAll('[role="tab"]')];
}) })
function setInputsState(section, disabled = false) {
section.querySelectorAll('input, textarea, button, select').forEach((el) => {
// console.log(el);
el.disabled = disabled;
});
}
tabs.forEach((tab) => { tabs.forEach((tab) => {
tab.addEventListener('hide.bs.tab', event => { tab.addEventListener('hide.bs.tab', event => {
const id_content_hide = event.target.getAttribute('data-bs-target'); const id_content_hide = event.target.getAttribute('data-bs-target');
const id_content_show = event.relatedTarget.getAttribute('data-bs-target'); const id_content_show = event.relatedTarget.getAttribute('data-bs-target');
console.log('==== Hide ===='); // console.log('==== Hide ====');
const content_hide = document.querySelector(id_content_hide); const content_hide = document.querySelector(id_content_hide);
content_hide.querySelectorAll('input, textarea, button').forEach((el) => { setInputsState(content_hide, true);
console.log(el);
el.disabled = true;
});
console.log('==== Show ===='); // console.log('==== Show ====');
const content_show = document.querySelector(id_content_show); const content_show = document.querySelector(id_content_show);
content_show.querySelectorAll('input, textarea, button').forEach((el) => { setInputsState(content_show);
console.log(el);
el.disabled = false;
});
}); });
if (!tab.getAttribute('aria-selected')) { if (!tab.getAttribute('aria-selected')) {
const id_content_hide = tab.getAttribute('data-bs-target') const id_content_hide = tab.getAttribute('data-bs-target');
const content_hide = document.querySelector(`#${id_content_hide}`); const content_hide = document.querySelector(id_content_hide);
content_hide.querySelectorAll('input, textarea, button').forEach((el) => { setInputsState(content_hide, true);
el.disabled = true;
});
} }
}) })