From 6d2b519484fbcb17d5163a37a0ebfd12ddac5367 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 2 Jan 2012 23:35:17 +0100 Subject: [PATCH] MINOR Auto-expanding nodes in TreeDropdownField, unsetting default titles when search field is focused --- javascript/TreeDropdownField.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/javascript/TreeDropdownField.js b/javascript/TreeDropdownField.js index e25c061e5..8b9457b40 100644 --- a/javascript/TreeDropdownField.js +++ b/javascript/TreeDropdownField.js @@ -120,9 +120,11 @@ var firstLoad = true; if(status == 'success') { $(this) + .jstree('destroy') .bind('loaded.jstree', function(e, data) { var val = self.getValue(); if(val) data.inst.select_node(treeHolder.find('*[data-id=' + val + ']')); + data.inst.open_all(); firstLoad = false; if(callback) callback.apply(self); }) @@ -141,6 +143,7 @@ // Avoid auto-closing panel on first load if(!firstLoad) self.closePanel(); + firstLoad=false }); } @@ -151,7 +154,7 @@ var self = this; return { 'core': { - 'initially_open': ['record-0'], + // 'initially_open': ['record-0'], 'animation': 0 }, 'html_data': { @@ -227,7 +230,7 @@ this.setTitle(title ? title : strings.searchFieldTitle); }, setTitle: function(title) { - if(!title) title = strings.fieldTitle; + if(!title && title !== '') title = strings.fieldTitle; this.find('.treedropdownfield-title').val(title); }, @@ -246,6 +249,14 @@ }); $('.TreeDropdownField.searchable input.search').entwine({ + onfocusin: function(e) { + var field = this.getField(); + field.setTitle(''); + }, + onfocusout: function(e) { + var field = this.getField(); + if(!field.getTitle()) field.setTitle(false); + }, onkeydown: function(e) { var field = this.getField(); if(e.keyCode == 13) { @@ -275,6 +286,7 @@ var firstLoad = true; if(status == 'success') { $(this) + .jstree('destroy') .bind('loaded.jstree', function(e, data) { $.each(self.getValue(), function(i, val) { data.inst.check_node(treeHolder.find('*[data-id=' + val + ']'));