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

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: Form Focus on Save

    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

  • cahickm2 Profile Picture
    cahickm2 12 on at
    RE: Form Focus on Save

    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
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: Form Focus on Save

    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.

  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 10,203 Super User 2025 Season 1 on at
    RE: Form Focus on Save

    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

  • cahickm2 Profile Picture
    cahickm2 12 on at
    RE: Form Focus on Save

    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
    Amit Katariya007 10,203 Super User 2025 Season 1 on at
    RE: Form Focus on Save

    can you share some screen shots that will be helpful.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans