javascript - JSTree Prevent drag from class -


afternoon, having few issues jstree 3.0. on load of page prevent nodes being dragged using dnd plugin. want able click edit button enable drag , drop functionality on nodes. think best way achieve set class on nodes , prevent drag if contains class. when edit clicked class removed.

i have found way class of node on move_node using data.node.li_attr.class. returns class cannot work out how stop drag operation. please see below code far:

$tree.on("move_node.jstree", function(e, data){             var nodeclass = data.node.li_attr.class;             if(nodeclass == "nomove")             {                 $.jstree.defaults.dnd_is_draggable(false);             }else{                 $tree.jstree("open_all");                 var nodeid = data.node.id;                 var nodeparent = data.parent;                 var level = data.node.parents.length;                 getchildren(data.node.id, level);                 var url = window.location.origin + window.location.pathname.replace(regexp, "/ajaxsavecasefamily");                  $.ajax({                     type:"post",                     url:url,                     data:{                         "_token":token,                         "nodeid":nodeid,                         "nodeparent":nodeparent,                         "depth":level                     },                     success:function(data){                         var query = data;                         if(query.result == "fail"){                             $("#errmsg").html(query.reason);                         }                     }                 })             }         }); 

any appreciated!

thanks in advance!!

you approaching wrong - when event triggered drag has begun - there function gets called determine if nodes draggable (even before dragging has started):
http://www.jstree.com/api/#/?q=is_dra&f=$.jstree.defaults.dnd.is_draggable

here example on how use it:

var is_dragging_allowed = false; $('#edit_button').on('click', function () {   is_dragging_allowed = true; }); $('#tree').jstree({   dnd : {     is_draggable : function () {       return is_dragging_allowed;     }, ... 

Comments