jsTree 3.0.0 - Rename node fails / resets. No event

2,693 views
Skip to first unread message

Alfred

unread,
Mar 27, 2014, 5:15:34 AM3/27/14
to jst...@googlegroups.com
Hi

Firstly tks for a great tool and the effort involved.


Using jsTree 3.0.0 (Beta 9) , I am having a problem with renaming a node. I can get it to go to 'edit' mode when I right-click and rename. But when I enter to accept new text value, it simply reverts to the original value.

I also get no rename.jstree (or rename_node.jstree) event firing.

I have put an example together at http://jsfiddle.net/ajpc6996/Amg2k/11/

I was using the standard ContextMenu, but have restricted it to just "Rename" for this fiddle. 


My code is below

      $('#treeTest').jstree({
            "core": {
                "data": [{"id":"1","text":"Node1"},{"id":"2","text":"Node2"}]
            },
            "contextmenu" : {
                    "items" : function ($node) {
                        return {
                            "Rename" : {
                                "label" : "Rename",
                                "action" : function (data) {
                                            var inst = $.jstree.reference(data.reference),
                                            obj = inst.get_node(data.reference);
                                            inst.edit(obj);
                                        }
                            }
                        };
                    }
                },
            "plugins" : [ "themes",  "dnd", "search", "types", "contextmenu", "crrm" ]  

        }).bind("rename_node.jstree", function (event, data) {
            alert(event.type);
        });

Has anyone got any pointers or advice as to where I'm going wrong ? Any assistance will be valued !

Regards,
Alfred

Ivan Bozhanov

unread,
Mar 27, 2014, 5:45:53 AM3/27/14
to jst...@googlegroups.com
http://www.jstree.com/docs/interaction/ : "Please keep in mind that by default all modifications to the tree are prevented (create, rename, move, delete). To enable them set core.check_callback to true"

That should fix the problem you are having.

Best regards,
Ivan

Alfred

unread,
Mar 27, 2014, 5:51:17 AM3/27/14
to jst...@googlegroups.com

Tks for the quick feedback Ivan !

It works now. I have updated the jsfiddle for future reference for other http://jsfiddle.net/ajpc6996/Amg2k/13/

Alfred

Harry Nijkamp

unread,
Jan 12, 2015, 2:58:11 PM1/12/15
to jst...@googlegroups.com
Hi Ivan,

I was struggling with renaming nodes when I found this article. 

Setting core.check_callback to true indeed helped out, but won't help in my case. I need to allow some operations ("move_node" and "copy_nodes") and forbid the rest of them in my project. Therefor my check_callback looks like this (see below). 

Unfortunately the "rename_node" operation will be triggered after typing and entering a new name. The rename textbox will not appear at all unless check_callbacks: true.

Any ideas on this situation? Thanks. 


'check_callback': function (operation, node, node_parent, node_position, more) {
                //console.log(operation);
                
                switch (operation) {
                    case "move_node":
                        return node_parent.id === '#' ? false : true;
                        break;
                    case "copy_node":
                        return node_parent.id === '#' ? false : true;
                        break;
                    case "create_node":
                        return operation === 'create_node' ? true : false;
                        break;
                }
            },

Ivan Bozhanov

unread,
Jan 13, 2015, 7:36:23 AM1/13/15
to jst...@googlegroups.com
Well, your check_callback does not handle the "rename_node" operation, so that is normal. Handle the "rename_node" case in the switch above.

Best regards,
Ivan

Harry Nijkamp

unread,
Jan 13, 2015, 1:32:37 PM1/13/15
to jst...@googlegroups.com
Hi Ivan,

I'm sorry.. I should have explained this better.

Even when I do handle the "rename_node" operation in the check_callback.. it does not work. 

The point is.. the "rename_node" operation seems to occur AFTER renaming the node. The textbox only occurs when check_callback is set to true. Setting the check_callback to the result of a function (like I did) won't show the textbox at all..

Hope this is better..

Harry



--
You received this message because you are subscribed to a topic in the Google Groups "jsTree" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jstree/cq9wzW9Ia3s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jstree+un...@googlegroups.com.
To post to this group, send email to jst...@googlegroups.com.
Visit this group at http://groups.google.com/group/jstree.
For more options, visit https://groups.google.com/d/optout.

Harry Nijkamp

unread,
Jan 13, 2015, 4:06:39 PM1/13/15
to jst...@googlegroups.com
I'm sorry (again) Ivan...

Suddenly I figured it out and got it working.. Many thanks.





Op 13 jan. 2015, om 13:36 heeft Ivan Bozhanov <ivan.b...@gmail.com> het volgende geschreven:

peter....@cossystems.com

unread,
Mar 19, 2017, 1:44:27 PM3/19/17
to jsTree
How?
Reply all
Reply to author
Forward
0 new messages