homelessDevOps
homelessDevOps

Reputation: 20726

Dojo 1.1: Event when leaving / switching tab?

We habe to use an old Dojo Version 1.1.x, our problem is to find an event fired when an Tab is changed (user leaving the tab).

Scenario: There is a Form inside an Tab, data is edited and the tab is left without saving, now we are looking for an way to prevent this.

    dojo.connect(this.myTabPoint, "onShow", function(evt){
        alert('X');
    });

Works fine, but so we have to implement the check on every other tab (;

Upvotes: 0

Views: 393

Answers (1)

phusick
phusick

Reputation: 7352

In Dojo 1.1.2 there is a method _hideChild(/*Widget*/ page) in dijit.layout.StackContainer (i.e. the superclass of dijit.layout.TabContainer), which will invoke onHide method of page/tab (e.g. ContentPane) if it exists.

The problem is there is no onHide method in dijit.layout.ContentPane, so you should add onHide stub method to ContentPane somewhere early in your code:

dojo.extend(dijit.layout.ContentPane, {
    onHide: function() {
        // stub method
    }
});

Then all you need to do is dojo.connect to onHide method on a particular tab/ContentPane:

dojo.connect(dijit.byId("tab1"), "onHide", function() {
    console.log("tab1 is hidden now");
});

Upvotes: 1

Related Questions