PDA

View Full Version : programmatically select a tab


tsailipu
09-01-2005, 04:51 PM
I saw some topics on disabling tab and selecting the previous one and some replies by Pablo (e.g. see the thread titled "Accessing tabs from code" ). But a search on "select a tab" didn't return any result. Seeing posts about how tabpane is missing some default events such as onselected, onclick, etc. and the post about the default set of tabs related components are just missing those events (see "Tabpane: I need an event to fire on select or click"), I guess for 3.0 or 3.0.2 in order to do this, I would have to look into the internals of how tabs, tabsbar, tabpane and tab work.

So I find a solution and am sharing here:

Basically, you can do:

"tabs".subviews[0].subviews["i"].setAttribute('click', true)

, where "tabs" is the name/id of your tabs/basetabs and "i" is the index number of the tabs you want to select/click programmatically. (The subviews[0] gets the tabsbar/basetabsbar member of the tabs/basetabs, which contains a list of tabs/basetabs.)

But, boy, isn't doing this non-intuitive and rather hacky (basically defeating the the purpose of black box/object encapsulation) for a behavior that we would expect from the out-of-box Laszlo tabs/tabspane/tab component? Is there a better way/cleaner way to do such? Or is Laszlo 3.1 providing such enhancement? If not, has anyone filed a feature request on this? Something like:

"tabs".[select|click]("tabpane_name"|"tabpane_id");

would have been great. (I guess there can be a set of utility methods like this, such as "hide"/"show", "enable"/"disable" a particular tab.)

Cheers,
Philip

bfagan
09-02-2005, 10:01 AM
Here's how I do it:

I have a tab class that extends the basetab. That class has an onmousedown event that specifies the tab clicked as the next tab in an attribute. This is so that I can see if data needs to be saved before I switch to the tab clicked.

When I'm sure that it's time to move to the new tab I do this:

(reference to tab clicked).setSelected(true);

tsailipu
09-02-2005, 11:07 AM
I see. It looks to be a different use case from what I have; I didn't elaborate on that in my first post.

What I aim to do is to be able to programmatically jump to a specified tab without the user's clicking on a tab -- this is useful, for example, when the user closes a tab, and I would like to direct the user to a tab that may be different from the last clicked-on tab.

The code snippet I shared can also help the use case that, for example, when there exists an index page of items, each of which can be opened into its own tab. When a user attemps to click on an item to open that item's tab, this code mechanism can be used to check whether that item's tab has been opened already and directly direct the user to that tab. (Perhaps such mechanism can be an enhancement to tabsbar class in that it can have an attribute, e.g. duplicate, that specified whether it is OK to open two tabs of the same name/id.)

Cheers,
Philip

spoco2
05-27-2007, 09:56 PM
I'm amazed there isn't more call for what you ask for in the first post.

Not being able to say basetabs.select(tabname/tabid) is criminal!

Inspecting a basetab and seeing nothing as to what's selected is very average indeed.

I hope that tabs are getting an overhaul in future releases.

My simple extension of basetabs gives this ability:

<class name="AppTabs" extends="basetabs">

<method name="setSelected" args="tabid">
this.bar.subviews[tabid].setAttribute('selected',true);
</method>

</class>

enachb
12-09-2008, 08:09 AM
Thanks for your solution! Works like a charm.

I second your opinion. It should be standard functionality.
The entire OpenLaszlo API/class model appears to be very well thought through, so as a newbie I was flabbergasted/frustrated when it didn't work.