Does dojo TabContainer have an event that fires when tabs change?

does DOJO Does TabContainer have an event that fires when tabs change?

I think it would be, but I could not find anything about this in the documentation. :(

SOLVED: Looks like I found a solution here:

Dijit TabContainer Events - onFocus

not the most popular topic title: /

+3
source share
4 answers

Connect aspect.afterto TabContainer method selectChild:

var tabContainer1 = registry.byId("tabContainer1");

aspect.after(tabContainer1, "selectChild", function() {
    console.log("tab changed");        
});

Or, if you are interested in a specific tab, connect to its ContentPane _onShow:

var contentPane1 = registry.byId("contentPane1");

aspect.after(contentPane1, "_onShow", function() {
    console.log("[first] tab selected");        
});

Look at the action in jsFiddle: http://jsfiddle.net/phusick/Mdh4w/

+5
source

From the documents

var tabs = registry.byId('someTabs');
tabs.watch("selectedChildWidget", function(name, oval, nval){
    console.log("selected child changed from ", oval, " to ", nval);
});
+3
source

@phusick, , StackContainer s, TabContainer , .

http://dojotoolkit.org/reference-guide/1.7/dijit/layout/StackContainer.html#published-topics

[widgetId]-addChild,
[widgetId]-removeChild
[widgetId]-selectChild

http://dojotoolkit.org/reference-guide/1.7/dojo/subscribe.html#dojo-subscribe

+2
source

Here is a complete sample code that works in Dojo 1.8, I tested it. This is not an event that fires only when the tabs change, I could not fire any of my events in the API, but at least it works in the Click event.

require(["dijit/registry",  "dojo/on", "dojo/ready", "dojo/domReady!"], function (registry, on, ready) {
    ready(function () { //wait till dom is parsed into dijits
        var panel = registry.byId('mainTab');   //get dijit from its source dom element
        on(panel, "Click", function (event) {   //for some reason onClick event doesn't work 
            $('.hidden_field_id').val(panel.selectedChildWidget.id);  //on click, save the selected child to a hidden field somewhere. this $ is jquery, just change it to 'dojo.query()'
        });
    });
});

//include this function if you want to reselect the tab on page load after a postback
require(["dijit/registry", "dojo/ready", "dojo/domReady!"], function (registry, ready) {
    ready(function () {
        var tabId = $('.hidden_field_id').val();
        if (tabId == null || tabId == "")
            return;
        var panel = registry.byId('mainTab');
        var tab = registry.byId(tabId);
        panel.selectChild(tab);
    });
});
0
source

All Articles