How do I know when a user switches between tabs?

1
I would like to know when a user switches between tabs. What is the best way to do this?   It seems that there is no 'on select' microflow or similar in the Mendix default tab container that can do this. I already tried to add a HTMLSnippet to catch the event using the following example: http://jsfiddle.net/mZLDk/ However in Mendix that gives me 'Error while evaluating javascript input: TypeError: $(...).tabs is not a function'. Any suggestions? Thanks,
asked
3 answers
4

Thanks for your valuable inputs, eventually I went for the following using the jquery enabled HTML snippet widget:

$( function() {
    var tabhrefs = $("[class^=mx-name-tabPage]");
    for (var i = 0; i < tabhrefs.length; i++) {
        tabhrefs[i].addEventListener("click", tabClicked);
    }
});

function tabClicked(event) {
    var target = event.target || event.srcElement; 
    console.log('Click on ' + target.innerHTML);
    // do something
};

A more Mendix integrated Dojo widget would indeed be nice too in case there are more users that need to act on tab changes.

answered
2

Can you post the full script? The way to go is to add an eventlistener to the tabpane change event of a dojo tabcontainer, see:

https://stackoverflow.com/questions/10549074/does-dojo-tabcontainer-have-an-event-thats-triggered-when-changing-tabs/14996881

answered
1

Hi Alexander,

In my personal experience Mendix i.e. dojo with its AMD and jQuery don"t go together very well.  That is why I would suggest to try and write any javascript code in pure i.e. vanilla javascript.
Here is how do the jQuery operations in javascript: Selecting objects

document.getElementById

registering event handler

object.addEventListener("select", myScript);

scheduling an onload "ready" event handler

window.onload = function() {

I hope this helps,

Andrej

answered