dojodijit.tree

How to enable openOnClick for a Dojo/Dijit Tree and still call onClick function


I want to be able to both select the folder node label to expand the tree while also calling the onClick function for the tree. I've set the openOnClick property of the tree equal to true which will enable the tree to expand when the node label is selected however then the onClick function is never called.

My code looks like this...

tree = new Tree({
    model: treeModel,
    openOnClick : true, // This prevents onClick function from firing
    onClick: function(item, node, event){
      // this function is never called because openOnClick is enabled
      alert("This message will never appear");  
    },
}, "tree");

I need both openOnClick and onClick to work. I am using dojo 1.9

Any ideas???


Solution

  • After digging through the dijit/Tree.js source code here was the solution I came up with.

    tree = new Tree({
        model: treeModel,
        // openOnClick : false, // Don't set openOnClick equal to true
        onClick: function(item, node, event){
          alert("This message will NOW appear!!!");
          this._onExpandoClick({node: node}); // This will expand the node
        },
    }, "tree");
    

    The logic in the Tree.js file checks the openOnClick value and based on its value will either expand the node or call the onClick function. I'm still not sure why the two functions are exclusive from one another.

    Does anyone know why this is?