selecting the first node and focus after move_node

562 views
Skip to first unread message

kofifus

unread,
Aug 11, 2015, 8:34:03 PM8/11/15
to jsTree


The first call to selectFirst() doesn't work, in the debugger I can see firstNode is false, why ? what is the correct way of getting and selecting the first root node ?

The second problem I have is with the focus disappearing which I think is maybe a bug. To reproduce run the jsfiddle, click on 'Root1' , click 'Del', then try to use the arrow keys.

Thanks !

Ivan Bozhanov

unread,
Aug 12, 2015, 1:39:44 AM8/12/15
to jsTree
Here is a fix to the first problem: https://jsfiddle.net/rsp2s88t/10/
You need to listen for the ready.jstree event before starting to work with the tree - in your code you were trying to access a node before it was rendered.

As for the focus - I believe this is because the focused node is moved into a closed node, hence losing focus (jstree can not restore the focus as the node is not visible). I will see if something can be done (aside from focusing the node manually of course).

Best regards,
Ivan

kofifus

unread,
Aug 13, 2015, 12:39:34 AM8/13/15
to jsTree
Thx Ivan,

I managed to solve the focus problem by adding inst.element.focus();

I stil not sure why is that needed, where does the focus go ?



Ivan Bozhanov

unread,
Aug 13, 2015, 1:40:00 AM8/13/15
to jsTree
I believe I explained what happens to the do focus - the focused node is moved inside a closed parent, so jstree can not restore the focused node (as it is inside a CLOSED parent).

Best regards,
Ivan

kofifus

unread,
Aug 13, 2015, 2:41:36 AM8/13/15
to jsTree
Hi Ivan,

I am seeing a lot of strange behavior and would love some help.

What I'm trying to achieve should be simple, it's a tree with a bin node and when you delete a node it is moved to the bin and the focus (&hover) stays where it used to be (that is move to the prev_dom)

Here is where I got to so far https://jsfiddle.net/rsp2s88t/13/

If you go around selecting and deleting nodes (with del)  and moving around with the keyboard a few times you'll see the blue square around the whole tree and/or the keyboard becomes unresponsive. This is despite me doing select_node and focus()

Any help ?

Thx!


Ivan Bozhanov

unread,
Aug 13, 2015, 9:45:53 AM8/13/15
to jsTree
Here you go: http://jsfiddle.net/rsp2s88t/15/

Best regards,
Ivan

kofifus

unread,
Aug 13, 2015, 7:33:35 PM8/13/15
to jsTree
works perfect Ivan , thank you :)

kofifus

unread,
Aug 13, 2015, 8:19:41 PM8/13/15
to jsTree
PS I think this is a bug or at least unexpected behavior. One does not expect having to set the focus manually after a move or select operation. Perhaps .children('.jstree-anchor').focus() can be added in the code to move_node or even better to select_node

Ivan Bozhanov

unread,
Aug 14, 2015, 1:54:09 AM8/14/15
to jsTree
As I explained earlier - the problem is with moving the node to a closed parent. As an experiment - leave the BIN folder open - you will see that after moving a node inside the opened BIN folder, it will stay focused. In your case you are both moving to a closed folder and wanting to change the focus to a new node - so a line of code is necessary.

I will however think about a general default behavior when focus is lost - like moving the focus to the first node.

Best regards,
Ivan
Reply all
Reply to author
Forward
Message has been deleted
0 new messages