🚀 Oracle APEX: Control Active Tabs in Tabs Container Using Custom Logic
🚩Introduction
At the same time, when the page is refreshed or submitted, users usually expect to stay on the same tab they were working on instead of being taken back to the first tab. To handle this properly, we can use a simple custom solution using Dynamic Action or JavaScript to track and control the active tab. This helps provide a smoother experience where tab selection behaves in a more natural and user-friendly way.
📑Why It is Essential to Track Tab Change in Tabs Container
In Oracle APEX, Tabs Container has a “remember tab” option that keeps the last selected tab, but it does not work well in all cases. For example, when a user comes from another page, the page may still open on the previously selected tab instead of showing the first tab by default.
To handle this properly, we need a simple custom solution to control the tab behavior. This ensures the first tab is selected when navigating from another page, while still allowing the same tab to be restored after a refresh or submit, giving a more consistent and expected user experience.
Navigate to the first tab when the user opens the page from another page
Keep the same tab when the page is refreshed or submitted
Control tab selection using custom logic instead of default behavior
-
Ensure a consistent and expected tab view for users
- Improve navigation experience in Oracle APEX Tabs Container
👉 Steps to Control Tab Navigation in Tabs Container
Step 1:
Step 2:
Step 3:
//Dynamic Action
var newTab = $(this.triggeringElement).find('a.t-Tabs-link[aria-selected="true"]');
var tabIndex = $('a.t-Tabs-link').index(newTab);
sessionStorage.setItem("ACTIVE_TAB", tabIndex); // you can give any name
//Dynamic Action
var newTab = $(this.triggeringElement).find('a.t-Tabs-link[aria-selected="true"]');
var tabIndex = $('a.t-Tabs-link').index(newTab);
sessionStorage.setItem("ACTIVE_TAB", tabIndex); // you can give any name
Step 4:
Now click on the page and navigate to the Execute When Page Loads section and copy paste the below javascript code to detect the page is navigated from other page or it is reloaded using performance browser function and this tells whether the page is navigated or reloaded based on this, we are setting the desired tab as active.
//Execute When Page Loads
(function() {
const TAB_KEY = "P4_ACTIVE_TAB";
var nav = performance.getEntriesByType("navigation")[0];
var $tabs = $('a.t-Tabs-link');
var savedTab = sessionStorage.getItem(TAB_KEY);
if (savedTab !== null && nav.type != "navigate") {
//if the page is not of type navigate then we are retaining the same tab
setTimeout(function () {
var $tabs = $('a.t-Tabs-link');
if ($tabs.length > 1) {
$tabs.get(savedTab).click();
}
}, 300);
}
else {
$tabs.first().trigger('click');
sessionStorage.setItem(TAB_KEY, 0);
}
})();
(function() { const TAB_KEY = "P4_ACTIVE_TAB"; var nav = performance.getEntriesByType("navigation")[0]; var $tabs = $('a.t-Tabs-link'); var savedTab = sessionStorage.getItem(TAB_KEY); if (savedTab !== null && nav.type != "navigate") { //if the page is not of type navigate then we are retaining the same tab setTimeout(function () { var $tabs = $('a.t-Tabs-link'); if ($tabs.length > 1) { $tabs.get(savedTab).click(); } }, 300); } else { $tabs.first().trigger('click'); sessionStorage.setItem(TAB_KEY, 0); } })();


Comments
Post a Comment