The Hide and Show Region templates provided with APEX provide a convenient way to load a bunch of data on a page and only display it when the user chooses to view it. It works well on a page where the page is normally viewed only once before navigating back or away to a different page.
They become a nuisance if you need to submit the page to do some processing and when the page reloads all the regions you had been showing are hidden again.
We can add two Dynamic Actions to a page where we want the hide and show regions to keep their open state when the page is reloaded. The first Dynamic Action will find all the visible hide and show regions and store their region ID in a cookie. The second Dynamic Action will read the values in the cookie and show the corresponding hide and show regions.
Dynamic Action 1
Name: Save Open Regions
Event: Before Page Submit
Condition: - No Condition -
True Action:
Action: Execute JavaScript Code
Fire On Page Load: [unchecked]
Code:
var lOpenRegions = []
$(".hide:visible").parent(".hide-show-region").each(function()
{ lOpenRegions.push($(this).attr("id")) });
SetCookie("HideShowOpenRegions",lOpenRegions.join(","));
Dynamic Action 2
Name: Open Saved Regions
Event: Page Load
Condition: - No Condition -
True Action:
Action: Execute JavaScript Code
Fire On Page Load: [unchecked]
Code:
if (GetCookie("HideShowOpenRegions")) {
$.each( GetCookie("HideShowOpenRegions").split(','),
function(intIndex, objValue) {
$("#"+$nvl(objValue,"x")+" .hide:first").show();
}
);
}
Click Here for Demo
=== UPDATE Sept. 9, 2014 ===
For Theme 26 and the "Hide and Show Region (Hidden First) - Borderless) template use the following:
Dynamic Action 1 Code:
var lOpenRegions = []
$("a.uRegionControl").not(".uRegionCollapsed").parents("section.uRegion").each(function()
{
lOpenRegions.push($(this).attr("id"))
});
SetCookie("HideShowOpenRegions",lOpenRegions.join(","));
Dynamic Action 2 Code:
if (GetCookie("HideShowOpenRegions")) {
$.each( GetCookie("HideShowOpenRegions").split(','),
function(intIndex, objValue) {
// $("#"+$nvl(objValue,"x")+" .hide:first").show();
$("#"+$nvl(objValue,"x")+" a.uRegionControl").click();
}
);
}