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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Form Focus on Save

(0) ShareShare
ReportReport
Posted on by 12

Good morning!

I have had the idea of only presenting users with only relevant tabs based on optionset value selections. I was able to come up with the following; it hides all tabs except the main input tab on load, it then displays the related tab on change. All is good there, however, on save the focus goes back to the main tab (on initial save only, subsequent saves focus remains where it should). On save how do I make it that the focus remains on the tab at the time of save?

function ToggleTab(executionContext) {
_formContext = executionContext.getFormContext();

var value = _formContext.getAttribute("xx_requesttype").getValue();
_formContext.ui.tabs.get("tab_5").setVisible(false);
_formContext.ui.tabs.get("tab_6").setVisible(false);
_formContext.ui.tabs.get("tab_7").setVisible(false);
_formContext.ui.tabs.get("tab_8").setVisible(false);
_formContext.ui.tabs.get("tab_10").setVisible(false);

if (value === 157420000)
_formContext.ui.tabs.get("tab_5").setVisible(true);
else if (value === 206340000)
_formContext.ui.tabs.get("tab_6").setVisible(true);
else if (value === 206340002)
_formContext.ui.tabs.get("tab_7").setVisible(true);
else if (value === 206340003)
_formContext.ui.tabs.get("tab_8").setVisible(true);
else if (value === 100000000)
_formContext.ui.tabs.get("tab_10").setVisible(true);
}

Thanks,

Corey

I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    can you share some screen shots that will be helpful.

  • cahickm2 Profile Picture
    12 on at

    On Load:

    pastedimage1673622967295v1.png

    On Change:

    pastedimage1673623101033v2.png

    Add data to the unhidden tab:
    pastedimage1673623180995v4.png

    Click Save and the focus goes back to the general tab:

    pastedimage1673623326803v5.png

    Subsequent saves the focus remains on the tab that has the focus when clicking save:

    pastedimage1673623410495v6.png

    I would like it to stay on the tab that was visible at the time save was clicked.

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    Hello,

    Can you try to use setFocus() function which will make your tab as primary.

    learn.microsoft.com/.../setfocus

    Refer below article which will help you to resolve your issue.

    carldesouza.com/.../

    Thank you,

    Amit katariya

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hello,

    You can use the formContext.ui.tabs.get method to get a specific tab by name and set focus on it.

    var tabName = "tab_name";

    var tabName = "tab_name";
    
    formContext.data.entity.save().then(
        function (saveResult) {
         formContext.ui.tabs.get(tabName).setFocus();
        },
        function (error) {
            console.log(error.message);
        }
    );


    It's important to keep in mind that you have to set the focus on the tab after the save event is completed, if you set it before the save it may not work properly.

  • cahickm2 Profile Picture
    12 on at

    I don't believe this will work. I want to set the focus to whatever tab has the focus, not a defined tab.

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hi cahickm2,

    1. You can add onchange event on the tabs on onload function and save the tab name in the query string. Once you save the record, you can retrieve the tab name and set the focus accordingly

    2. You can get the display state of all the tabs and look for the expanded tab. It will give you the current active tab and you can set focus then.

    learn.microsoft.com/.../getdisplaystate

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans