Question

I'm trying to do a very simple thing and seem to have hit a brick wall. It may already be in the docs but I failed to find it.

I'm trying to save a newly created node or a renamed one. I'm starting with a very basic setup:

$('#tree').jstree({
    'core' : {
        'check_callback' : true
    },
    'plugins' : ['contextmenu', 'dnd', 'state']
}).on('create_node.jstree', function(e, data) {
    console.log('saved');
});

What I'm expecting is:
1) Right click on one of existing nodes.
2) Click "create" - that's when console.log('saved'); fires
3) I type in a name of a new node
4) Press "enter" to save the data - at this point I want to run an ajax request to save new node in DB.

How do I catch the event from point 4) ?

Was it helpful?

Solution

Author of the plugin suggested to listen for the rename_node event. So the working code is:

$('#tree').jstree({
    'core' : {
        'check_callback' : true
    },
    'plugins' : ['contextmenu', 'dnd', 'state']
}).on('rename_node.jstree', function(e, data) {
    console.log('saved');
});

OTHER TIPS

At times if this doesn't work and you wanted to go for create_node event, then use,

$('#tree').jstree({
'core' : {
    'check_callback' : true
},
'plugins' : ['contextmenu', 'dnd', 'state']
}).bind('create_node.jstree', function(e, data) {

console.log('saved');

});

this might just do the trick. Or if atall if it is being used in some pop-up use the live event instead of on event of jquery, that will surely hit the spot.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top