0

I am trying to move nodes within the the jstree(which is build from a json_data).

When i move the node i want to display a confirmation that "Are you sure you want to move?". I do this using the following code.

   $("#demo2").bind("before.jstree", function (e, data) {

       if(data.func == "move_node"  && data.args[1] == false && data.plugin == "core")
       {
            if (confirm('Are you sure you want to move?') === false) {
               e.stopImmediatePropagation();
               return false;
            }
       }

});

But this "Are you sure you want to move?" confirm message is displayed twice.

May i know how to fix this ? I am using latest jstree,jquery commit.And i am not using crrm plugin.I am using only dnd plugin.

Please advise.

Regards, Peri


Thanks for your reply Chris. I tried this but still not working. The alert appears twice here also. Please advice. $("#demo2").bind("before.jstree", function(e, data) { try{ var flag = 1; var nodeMoved = data.args[0].o; } catch(e){ flag = 0; } if (data.func == "move_node" && data.args[1] == false && data.plugin == "core" && flag == 1) { // alert(data.func + "---" + data.args[1] + "---" + data.plugin); if(!confirm("Are you sure you want to move?")) { e.stopImmediatePropagation(); return false; } } });

2 Answers 2

0

I haven't run into this myself, but I've read about the issue on the jstree user group. I believe at this time the only solution would be to create a global javascript flag. Once the user has indicated yes/no you could key off that to prevent the extra pop-ups. Of course you need to clear the flag afterwards so you don't suppress future move confirmation prompts.

Also, I've noticed that in the multiple calls to before.jstree where data.func == "move_node" only ONE of them has defined data.args[0].o (see _get_move for a description of the objects frequently used in jstree data). So you could modify your code to something like this as an alternative to the global flag (I've played with this but haven't put in production YMMV):

if(data.func == "move_node"  && 
   data.args[1] == false && 
   data.plugin == "core" &&
   data.args[0].o != undefined)
   {
        // your work goes here...
   }
1
  • Thanks for your reply Chris. I tried this but still not working. The alert appears twice here also. Please advice. $("#demo2").bind("before.jstree", function(e, data) { try{ var flag = 1; var nodeMoved = data.args[0].o; } catch(e){ flag = 0; } if (data.func == "move_node" && data.args[1] == false && data.plugin == "core" && flag == 1) { // alert(data.func + "---" + data.args[1] + "---" + data.plugin); if(!confirm("Are you sure you want to move?")) { e.stopImmediatePropagation(); return false; } } });
    – Peri
    Aug 1, 2011 at 5:12
0

I know this question is a million years old but I just ran into the same issue here. I don't really know what the problem is but I found that adding a reference to the "crrm" plugin solves it. I suppose it might be caused by the fact that "core" duplicated the "get_move" and "check_move" functions but I didn't look into it much further...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.