-1

My dynatree looks something like this :-

                                               |---- Their Car
                       |----------- Cars ----- |---- My Car
                       |
   Objects ----------- |----------- Boats -----| --- My Boat
                       |                       | --- Your Boat
                       |                       | --- custom1_Your Boat
                       |                       | --- custom2_Your Boat
                       |
                       |----------- Bikes1 -----| --- Your Bike
                       |----------- custom1_Bikes1 -----| --- My Bike

I want the user to be able to select one node among Bikes1 and custom1_Bikes1 and Your Boat, custom1_Your Boat and custom2_Your Boat. The rest of the nodes should be multi-selectable

Here's what I've tried so far

 $(function(){
    $("#tree").dynatree({
    checkbox: true,
    selectMode: 2,
    initAjax: {
        url: 'get-list.php'
    },
    onSelect: function(flag, node){
        if (flag) {
            var siblings = node.getParent().getChildren();


            if((node.data.title).indexOf('custom') >= 0) { // If node contains the string 'custom'

            for( var x in siblings) { // Loop through the sibling nodes


                if(((node.data.title).split('_')[1] == x.data.title) || x.data.title.indexOf('custom') >= 0) { // Check if there is another node containing 'custom' or if there's a node with the same name after '_'
                     x.select(!flag); //deselect that node
                }

            }

            }

            else {   // If the node doesn't contain the string 'custom'

                for (var x in siblings) { // Loop through sibling
                if((x.data.title).indexOf('custom') >= 0) { // Check if there is a node with string 'custom'
                     x.select(!flag); //deselect that node
                }
               }
             }
          }
         }
         // Do something else with the list of selected nodes

        });
    });

It seems that the nodes aren't being automatically deselected and I'm wondering if selectMode:2 is overriding the programmed behavior

anath2
  • 71
  • 2
  • 7

1 Answers1

0

Answering my own question, the problem was in how I was looping through siblings .

Here's the corrected code :

$(function(){
var inEventHandler = false;
$("#tree").dynatree({
    checkbox: true,
    selectMode: 2,
    initAjax: {
        url: 'get-list.php'
    },

    onSelect: function(select, dtnode) {   
        if (select) {
            var siblings = dtnode.getParent().getChildren();


            if((dtnode.data.title).indexOf('custom') >= 0) { //Check if it's a custom dtnode

            for( var i = 0; i < siblings.length; i++) { // Loop through sibling nodes


                if(((dtnode.data.title).split('_')[1] == siblings[i].data.title) || (siblings[i].data.title.indexOf('custom') >= 0 && siblings[i] != dtnode )) { // Check if there is another custom dtnode or base base dtnode 

                     siblings[i].select(false); //deselect that dtnode
                }

            }

            }

            else {

               for (var i = 0; i < siblings.length; i++) {
                  if((siblings[i].data.title).indexOf('custom') >= 0) { // Check if there is another custom dtnode 

                     siblings[i].select(false);
                   }
               }


            } 
       }

     // Do something with the selected nodes
     }  
});
});
anath2
  • 71
  • 2
  • 7