PaperParser/app/blueprints/frontend/static/tabs.js

36 lines
1.2 KiB
JavaScript

const tabs_lists = document.querySelectorAll('.nav-tabs[role="tablist"]');
let tabs = [];
tabs_lists.forEach((tabs_list) => {
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;
});
}
function tabSwitchHandler(event) {
const id_content_hide = event.target.getAttribute('data-bs-target');
const id_content_show = event.relatedTarget.getAttribute('data-bs-target');
// console.log('==== Hide ====');
const content_hide = document.querySelector(id_content_hide);
setInputsState(content_hide, true);
// console.log('==== Show ====');
const content_show = document.querySelector(id_content_show);
setInputsState(content_show, false);
}
tabs.forEach((tab) => {
tab.addEventListener('hide.bs.tab', tabSwitchHandler);
if (tab.getAttribute('aria-selected') == "false") {
let id_content_hide = tab.getAttribute('data-bs-target');
let content_hide = document.querySelector(id_content_hide);
setInputsState(content_hide, true);
}
})