Issue 484: The focus(true) does not work for a node within the loadkeypath function
Status:  WontFix
Owner: ----
Closed:  Apr 2014
Reported by bestellu...@googlemail.com, Apr 20, 2014
What steps will reproduce the problem?

1.) If you look at the if branch there is activated AND focused the foundNode. Setting the focus works fine here

2.) If you look at the else branch there happens the same as in 1.) BUT setting the focus on the node does NOT work!

There must be a problem with the loadkeypath function and focus because EVERYWHERE else in my app the focus(true) works fine.

If possible, please attach an example HTML file (e.g. a copy of `doc/_test-
ISSUE.html`), that reproduces the problem when copied
into the dynatree/doc/ folder or reproduce on jsFiddle:

Sorry more than this code I can not uploaded.

/******************* CODE ***************************************/
 $("#searchfield").autocomplete({
            select: function (event, ui) {
                var tree = $("#TreeDiv").dynatree("getTree");
                var unitId = ui.item.UnitId;
                var foundNode = tree.getNodeByKey(unitId.toString());
                if (foundNode) { // the nodes parents were already lazy loaded/expanded
                    foundNode.activate(true);
                    foundNode.focus(true);
                }
                else { // the node is not found because I have to load the node and its parent first
                    var loadkeyPath;
                    $.getJSON('@Url.Action("SelectUnits","Unit")', { unitId: unitId }, function (units) {

                        // Add the searched UnitId at the end
                        units.push(unitId);
                        loadkeyPath = units.join(';');

                        tree.loadKeyPath(loadkeyPath, function (node, status) {
                            if (status == "loaded") {
                                node.expand();
                            } else if (status == "ok") {
                                node.activate(true);
                                node.focus(true);
                                var activeLi = node.li;

                                $('#TreeDiv ul').animate({
                                    scrollTop: $(activeLi).offset().top - $('#TreeDiv ul').offset().top + $('#TreeDiv ul').scrollTop()
                                }, 'slow');

                            } else if (status == "notfound") {
                                console.log('node not found');
                            }
                        });
                    });
                }

                return false;
            },
/*********************************************************************/

What version of the dynatree and jQuery are you using?
On what operating system and browser?
What DOCTYPE declaration are you using?

dynatree version 1.2.5
jquery version 2.1
Windows 8 x64
IE11 or Chrome35

Please provide any additional information below.

My tree settings:

$('#TreeDiv').dynatree({
            onLazyRead: function (node) {
                node.appendAjax({ url: '@Url.Action("GetChildrenUnits", "Unit")', data: { "unitId": node.data.key } });
            },
            onPostInit: function (isReloading, isError) { // When the rootnode is loaded with the 1th level children the onPostInit should not be needed
                var rootnode = $("#TreeDiv").dynatree("getRoot");
                var children = rootnode.getChildren();
                var firstNode = children[0]; // The first node of the hidden dynatree rootNode is MY root node
                firstNode.toggleExpand();
                firstNode.activate(true);
                firstNode.focus(true);
            },
            keyPathSeparator: ";",
            children: data,
            activeVisible: true,
            onClick: function (node) {

            // do stuff
            },
            imagePath: '~/Content/skin/',
Apr 20, 2014
#1 bestellu...@googlemail.com
I use HTML5 DocType
Apr 23, 2014
Project Member #2 moo...@wwwendt.de
I won't be able to fix this for Dynatree (unless someone sends a patch) since I am focused on Fancytree now.
If possible, feel free to try and open an issue there, if the problem should still exist.
Status: WontFix
May 2, 2014
Project Member #3 moo...@wwwendt.de
Cleanup Scrumboard
Labels: Milestone-Release2.0