2281
Views
19
Comments
Set the active tab in tabs pattern for reactive web apps
Question

Hi,

I am using the tab pattern in a reactive web app. In traditional web I could set the active tab with a variable. How can I do such a thing in reactive? 

In particular our customer has the option of shortcuts that are bound to buttons. With this shortcuts some data will be updated and we want to switch to the tab where more details for that update are shown. e.g. a new entry in a list.

2026-02-26 06-29-24
Rahul
 
MVP

Hi Philipp,

you have option in Rective web nevigation/Tab in outsystem UI

Here is a option starting tab you can assign integer variable in this.


Hope this will help you

Regards

Rahul Sahu

2020-03-12 15-06-24
Steven Decock

Hi Philipp,

We had the same problem.  StartingTab is probably not going to help you.  It only works to set the initial tab, you cannot use it to switch the tab afterwards.

You can switch the tab using javascript though.

We created a TabSwitcher component on our project to make this easier (see attachment).  It uses the javascript function.  Check the code if you want to know how it works.

You can put your Tabs component in the 'TabsPlaceholder' placeholder of the TabsSwitcher component.

The TabSwitcher takes the ActiveTab as an argument.  You can then change the ActiveTab input parameter for the TabSwitcher to switch tabs.

That should solve your problem.

We've also created a support case to solve this in the Tabs component itself by the way.  Seems to me like StartingTab should be renamed to ActiveTab and should have this ability built in.



Best regards,

Steven


TabSwitcher.oml
2021-03-04 09-06-22
Oscar Moya

Thanks Steven

Your block works perfectly!

2023-12-20 21-15-17
Rob Poels

Hi Steven,

I am facing the same problem as Philipp is, and tried your 'TabSwitcher' solution.
Unfortunately it does not work for me.
I enclosed my TabControl in the TabSwitcher, and added an 'ActiveTab' variable to set the current tab. When changing the ActiveTab value nothing happens however. Initializjng the 'ActiveTab' to 2 for instance neither has success.

Is there something I might have missed?

Regards,
Rob.

2020-03-12 15-06-24
Steven Decock

Hi Rob,


Can you upload an .oml file where you have this problem?  Without seeing your code it's hard to know why it doesn't work.


Regards,

Steven

2023-12-20 21-15-17
Rob Poels

Steven Decock wrote:

Hi Rob,


Can you upload an .oml file where you have this problem?  Without seeing your code it's hard to know why it doesn't work.


Regards,

Steven


Hi Steven,

Sorry for my late reaction, but I managed to get it working:I create an event handler for the 'OnTabChange' event and assigned the 'ActiveTab' variable there. Then it worked for me.

Regards,
Rob

2020-05-11 08-55-25
Lena Vahle

You don't need an extra web block for that. Simply use javascript document.getElementById("$b2").changeTab($parameters.newIndex). The $b2 is my id of the Navigation.Tab datablock. You can simply find when inspecting an element in chrome. The id does not change if you don't change the navigation tab. 

UserImage.jpg
Soon

Lena Vahle wrote:

You don't need an extra web block for that. Simply use javascript document.getElementById("$b2").changeTab($parameters.newIndex). The $b2 is my id of the Navigation.Tab datablock. You can simply find when inspecting an element in chrome. The id does not change if you don't change the navigation tab. 

 Thanks for the hint and it works perfectly for me!

 

2017-06-06 09-43-03
Frans Moquette

Thanks, solved it for me and my team.

If I may suggest a small improvement to your code, to make it more generic, pass the NavigationTabs widget id as a parameter, like so:

document.getElementById($parameters.NavTabId).changeTab($parameters.newIndex)

You'll need to give the NavigationTabs widget a name in Service Studio to be able to set the value.


2021-03-04 09-06-22
Oscar Moya

Great Lena,

It worked


Thanks

UserImage.jpg
Bestlin Louis

Hi,

I am new to Outsystems.

I did not understand the solution.

Kindly share a sample code for the same with working tab switch.

Thanks in Advance.

2017-08-13 19-08-40
Pedro Antunes

Another solution is to work with the element's attribute and simulate a click on the TabsHeaderItem. More for error cases where the changeTab action is not available.

Example: 

Solution:


The ParentElementID (input parameter) is from the Tabs (You need to name the element):


Script: document.querySelector('#' + $parameters.ParentElementID + ' button[data-tab="' + $parameters.ActiveTab + '"]').click();


NOTE

I tested OutSystemsUI SetActiveTab widget. But this widget just makes the TabsHeaderItem active. Does not change the Content of Tabs


2022-09-20 06-28-12
Nitish Kumar

Hi Pedro Antunes,

This solution worked for me

Thanks

2023-02-02 14-34-34
Yini Zhang

Hi @Pedro Antunes , could you pls kindly update your test oml?:) It would be very helpful for us, thank you in advance! 

BR, Yini

2023-03-06 13-49-27
Hugo Rodrigues

This solution worked perfectly for me, thanks Pedro.

2023-02-02 14-34-34
Yini Zhang
test2.oml
2017-08-13 19-08-40
Pedro Antunes

Hello Yini.

I could see in debugging that the problem is that you are passing an ID (Text) to the Data-Tab. This value must be an integer. You must pass a number (INT) of the TAB you want to activate 



I send the OML with the resolution and comments. Take a look. I also added some actions to test things out. 


Hope you can figure out the problem and solve it. 

Best regards.

Pedro Antunes

ChangeActiveTab.oml
2021-09-27 12-33-31
Hugo Montenegro

you can use $actions.SetActiveTab(WidgetId,TabsNumber); from outsystems in javascript and pass the main id and which tab you want to be active when you run the javascript.

Ex:
$actions.SetActiveTab($parameters.ParentElementID,2); 

Best regards,
Hugo Montenegro

2024-06-12 16-40-09
Angelo Milella

Seems to be best today 01/24/2025, the rest DID NOT WORK for me.

Using the native Outsystems functions is always the best thing in these cases, they have perhaps changed the logic and today it seems to me to be the only way to do something simple and clean

$actions.SetActiveTab($parameters.TabNav,1)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.