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.
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
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
Thanks Steven
Your block works perfectly!
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.
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 Decock wrote:
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
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.
Lena Vahle wrote:
Thanks for the hint and it works perfectly for me!
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.
Great Lena,
It worked
Thanks
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.
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
Hi Pedro Antunes,
This solution worked for me
Hi @Pedro Antunes , could you pls kindly update your test oml?:) It would be very helpful for us, thank you in advance!
BR, Yini
This solution worked perfectly for me, thanks Pedro.
@Pedro Antunes Here.:)
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
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
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)