I need to execute an ajax call after the user moves a node in a jsTree using the dnd plugin. If that ajax call returns an error, I need to either prevent the move from happening, or reverse the action altogether. From the move_node
event listener, is there a way to tell the dnd plugin to reverse the drop or somehow cancel the action? I've tried returning false
and setting e.preventDefault()
and e.stopImmediatePropagation()
but nothing seems to work.
$($tree).jstree({
core: {
data: $treeData,
check_callback: function (op, node, parent, position, more) {
switch (op) {
case 'move_node':
// moveNode() validates the move based on
// some data stored in each node, but doesn't
// (and shouldn't) make an ajax call to determine
// if the node *actually can* be moved
return moveNode(node, parent, position, more);
}
}
},
plugins: ['dnd']
}).on('move_node.jstree', function(e, data) {
// moveNode() returned true and the user moved the node
if (!doMoveNode(data)) {
// none of this works!!
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
});
I figured this out... the key is to intercept the move before it happens, which can be done in the
check_callback
as so: