Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Inna on Dec 02, 2008 14:27
open dhtmlx forum
re: dhtml tree duplicate children for the same parent

Thank you, logic below worked:

var ids=tree.getAllSubItems(0).split(",")
var check={}
for (var i=0; i<ids.length; i++){
var label=tree.getItemText(ids[i]);
if (!check[label]) check[label]=true;
else tree.deleteItem(ids[i]); //delete duplicate

However, I would like to keep duplicate node highlighted, and return it's default value ( ex: New Item[1] ). I am trying to use stopEdit(), it doesn't work:

var hasChildrenCheck = tree.hasChildren(treeitemId);
                tree.attachEvent("onEdit",function(){
                var booleanVar = true;
                if(hasChildrenCheck > 0 ){
                var ids = tree.getAllSubItems(treeitemId).split(",");
                var check={};
                for (var i=0; i<ids.length; i++){
                
                var label=tree.getItemText(ids[i]);
                 if (!check[label]) {
             check[label]=true;
                    booleanVar=true;
                    }
                else {
             //    tree.focusItem(selectedItem);            
                tree.stopEdit();
            //    tree.deleteItem(ids[i]); //delete duplicate
                booleanVar=false;
                }
                }
                } return booleanVar;
});

Please help,
Thank you
Answer posted by Support on Dec 03, 2008 02:09
IF you want to prevent duplicates as result of in-tree edit, it can be done as 


tree.attachEvent("onEdit",function(stage,id,tree,value){
     if (stage==2){ //before editor closed
          var ids=tree.getAllSubItems(0).split(",");
          for (var i=0; i<ids.length; i++)
               if (tree.getItemText(ids[i])==value) return false; //revert to old value if there is a duplicate
    } 
    return true;
})