web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Preventing Initial Fla...
Power Apps
Unanswered

Preventing Initial Flash of All Tabs in Model-Driven Power Apps Form

(1) ShareShare
ReportReport
Posted on by 8

Hello everyone,

I am working on a model-driven app and I have a requirement to show/hide specific tabs based on the viewId parameter in the referrer URL. I have written a JavaScript function that fetches the viewId and hides or shows the corresponding tab accordingly.

 

function tabVisibilityControl(executionContext) {
 console.log("Script started!");

 var formContext = executionContext.getFormContext();

 // Get the viewId from referrer URL
 var urlString = document.referrer;
 var url = new URL(urlString);
 var viewId = url.searchParams.get("viewid");

 // Configuration mapping viewId to tab names
 const config = {
 "7cd3ad3e-23e0-4bab-9470-6baf46a5f9b0": "tab_0",
 "46ac8c12-2ce6-ee11-a203-6045bd71ec9a": "tab_1",
 "73bd2f05-7ee6-ee11-a203-6045bd71ec9a": "tab_3",
 "abb63b2d-7ee6-ee11-a203-6045bd71ec9a": "tab_4",
 "e9929e57-7ee6-ee11-a203-6045bd71ec9a": "tab_5",
 "b9ea787f-7ee6-ee11-a203-6045bd71ec9a": "tab_6"
 };

 // Check if viewId exists in the configuration and hide/show tabs accordingly
 if (viewId && config.hasOwnProperty(viewId)) {
 showTab(config[viewId]);
 } else {
 console.warn("ViewId not found in the configuration.");
 hideTabs(); // Hide all tabs if viewId not found
 }

 /*
 Function to show the appropriate tab and hide others
 @Param {string} visibleTabName - The name of the tab to make visible
 */
 function showTab(visibleTabName) {
 var tabs = formContext.ui.tabs.get();
 tabs.forEach(function (tab) {
 var tabName = tab.getName();
 var tabElement = document.querySelector("[data-id='" + tabName + "']");
 if (tabElement) {
 if (tabName === visibleTabName) {
 tabElement.classList.remove("hidden-tab");
 tab.setVisible(true);
 } else {
 tabElement.classList.add("hidden-tab");
 tab.setVisible(false);
 }
 }
 });
 }

 /*
 Function to hide all tabs
 */
 function hideTabs() {
 var tabs = formContext.ui.tabs.get();
 tabs.forEach(function (tab) {
 var tabName = tab.getName();
 var tabElement = document.querySelector("[data-id='" + tabName + "']");
 if (tabElement) {
 tabElement.classList.add("hidden-tab");
 tab.setVisible(false);
 }
 });
 }
}

 

When the form loads, all tabs are briefly visible before the script runs and hides them. This causes an undesirable flash of all tabs, which negatively impacts the user experience.

Is there a way to hide all tabs before the form fully loads and then show the appropriate tab after my script runs? How can I prevent the initial flash of all tabs on form load?

Any suggestions or best practices for handling this scenario in model-driven apps would be greatly appreciated!

Thank you in advance for your help!

 

Categories:
I have the same question (0)
  • Giraldoj Profile Picture
    943 Moderator on at

    Hi @priya_ 

     

    perhaps you can try the opposite, hide all tabs by default and then only show the ones you are interested.

     

    something like this 

    function showTabOnLoad(executionContext) {
     var formContext = executionContext.getFormContext();
     
     // Get the tab you want to show
     var tab = formContext.ui.tabs.get("tab_1");
     
     // Check if the tab exists and show it
     if (tab) {
     tab.setVisible(true);
     }
     }
    
    //rest of the code

     

    If my response resolved your issue, please feel free to mark it as the solution by clicking accept it as a solution

    If you liked my solution, please give it a thumbs up
    This helps others find the answer more easily.

    Connect with me: LinkedIn 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 342 Most Valuable Professional

#2
11manish Profile Picture

11manish 234

#3
Valantis Profile Picture

Valantis 187

Last 30 days Overall leaderboard