1

How do you test whether a tab is active or not with a dojo tab container? (In JQuery this is simple... you can use something like this

if($("#accordion").accordion('option', 'active') == mytabNumber){

With dojo's, dijit.layout.TabContainer there must be a similiar way to do it without having to write a litener function and all that jazz.

perhaps something like...

if( dojo.byId("tab2"), {selected:true} ){

Thanks in advance!

lance
  • 43
  • 1
  • 9

3 Answers3

6

You can compare the widget for the tab with the tab container's selectedChildWidget property, i.e.:

dijit.byId('tabContainer').selectedChildWidget == dijit.byId('tab2')

Mara Morton
  • 4,429
  • 1
  • 21
  • 12
  • Looks like .id is actually a property of the .selectedchildwidget object... so you can simplify this as... dijit.byId('tabContainer').selectedChildWidget.id = "tab2" – lance Jun 29 '11 at 22:59
2

If you have a reference to the tab already, you can simply just check its 'selected' property to see if it's selected, regardless of the container it is in.

var tab2 = dijit.byId('tab2');
if (tab2.get('selected')) { /* do stuff */ }

I've created a more detailed example at http://jsfiddle.net/brianarn/ws28T/

Brian Arnold Sinclair
  • 3,833
  • 1
  • 21
  • 16
0

Here's more complete code answer that gives the surrounding code for Dojo 1.8:

require(["dijit/registry",  "dojo/ready", "dojo/domReady!"], function (registry, ready) {
    ready(function () { //wait till dom is parsed into dijits
        if (dijit.byId('tabContainer').selectedChildWidget == dijit.byId('tab2'))
            alert('Yes, we found it!');
    });
});
Richard
  • 14,798
  • 21
  • 70
  • 103