Can any security or enabling be set for individual tabs on a tab container, or a way to make them hidden? Why let users drool over things they can’t have access to?
I don’t know about container security, though I suspect you can. I do know that you can set visibility using the session/props/auth/securitylevels property, so maybe take a look at that.
I don’t want to hide the entire container, just certain tabs.
From what I’ve tried, you can sort of hide tabs like what you’re asking, but it’s a bit of a puzzle and might have some side effects.
The way I tried was to have a binding on props.tabs
to session.auth.user.roles
with a script transform. You can choose which tabs to show or hide programatically based on the roles the user has (assuming they’ve signed in). In removing an element from the props.tabs
array, the view in the tab container will continue to exist while removing the tab on the top (and thus the ability to swap to that tab).
The thing that makes this difficult is that the views you drag into the tab container will always match the index of the tab. This means if you had 3 tabs with 3 views, and you wanted to hide the middle one, you couldn’t; you would have to put the middle view at the end. If you were to delete the middle item in the props.tabs
array (thinking you could hide the tab), the last item in the array would slide left, and your 2nd tab would have the 3rd tab’s text, but would show the 2nd tab’s view.
Ex:
So, the problem gets complex if you’re trying to hide more than a couple views, or if you want to have many different configurations.
If you do need something with more control, you could do something like put embedded views into each tab, then use a property change script on your tab container’s props.currentTabIndex
to send system.perspective.sendMessage()
messages with payloads denoting which view to show at which index (which your embedded views would then need to handle).
Sorry for the wall of text; this was a harder problem to approach than I originally thought, lol.
Sounds like a good candidates for an ideas suggestion
@kirsten.chambers: Yeah that was the rabbit hole I was trying to avoid.
@PGriffith: Done and done.
I realize it's been a few years, BUT how about adding "disabled" to the normal/non-object tab index? I left a comment on Jordan's feature request via the link, this would be nice too!
How would an index item have more than one property if it were not an object?
Bump. Solved this using expressions. Didn't see a solution shared.
EPA tab is the one I hide or show.
Script to change tabs.
Script to change tabIndex. One to remove tab and one to change index number.
Script on EPA Tab view. Tab to hide. To hide, I used -1.
Script on Alarm Tab view. Tab to shift. When the 3rd tab is removed, the 4th tab is changed to the 3rd tab.
EPA tab present.
EPA tab hidden.
I think this solution only works if you're hiding the last item in the tabs array.
If you re-arrange your list so that EPA is in front of DB, then switching to DB will open the EPA container view.
I ended up rolling my own with a tab strip using flex repeater for tabs and various message handlers to change the embedded view path.
The last tab Alarms also has a script to change the tab number. From 4 to 3. I used scripts to change the tab embedded views to match the active tab position. Worked for me.
The main issue I ran into with any manipulation of the tab container was when I had a tab strip
Opt 1, Opt 2, Opt 3, Opt 4
Admin logs in I want all 4
Supervisor logs in I want 2,4
Operator logs in I wanted just 3
Toggling in this scenario makes a very limited/ non-scalable solution.
Ia added a disabled
prop to each tab if you make them objects, along with a disabledStyle so you can style disabled tabs how you like. If you want the disabled tab taken out of the flex then add display: none
.
I detail this here
You should not dynamically generate your tabs array otherwise your tab contents' view indexes will become dislodged, and trying to maintain these via script based on the tabs that are there is just a nightmare
I've done this with a startup script. Basically, figure out which tabs you want to show, use a script to create a list, and then pass that list to the tab container tabs property. The script also needs to manage the tabindex of each embedded view/container to match, so the correct tabs match with the correct views. But it can be done.
For restrictive components, for example this one if can edit or no a textField,
I use some expression like:
coalesce({session.custom.editEnabled}, false)
that´s defined on my Session Startup:
if notes:
try:
parts = notes.split(";")
for part in parts:
if part.startswith("edit:"):
edit_flag = part.split(":")[1]
edit_enabled = (edit_flag.strip() == "1")
That linked to the notes area of the user in the gateway