MINOR Unselect a selected node in TreeDropdownField (for lack of better unselect UI)

This commit is contained in:
Ingo Schommer 2012-01-05 23:16:12 +01:00
parent 6edf055dff
commit e517abf2b2

View File

@ -152,8 +152,9 @@
$(this) $(this)
.jstree('destroy') .jstree('destroy')
.bind('loaded.jstree', function(e, data) { .bind('loaded.jstree', function(e, data) {
var val = self.getValue(); var val = self.getValue(), selectNode = treeHolder.find('*[data-id="' + val + '"]'),
if(val) data.inst.select_node(treeHolder.find('*[data-id="' + val + '"]')); currentNode = data.inst.get_selected();
if(val && selectNode != currentNode) data.inst.select_node(selectNode);
data.inst.open_all(); data.inst.open_all();
firstLoad = false; firstLoad = false;
if(callback) callback.apply(self); if(callback) callback.apply(self);
@ -161,12 +162,14 @@
.jstree(self.getTreeConfig()) .jstree(self.getTreeConfig())
.bind('select_node.jstree', function(e, data) { .bind('select_node.jstree', function(e, data) {
var node = data.rslt.obj, id = $(node).data('id'); var node = data.rslt.obj, id = $(node).data('id');
if(self.getValue() == id) { if(!firstLoad && !self.getValue() == id) {
// Value is already selected, unselect it (for lack of a better UI to do this)
self.data('metadata', null); self.data('metadata', null);
self.setTitle(null); self.setTitle(null);
self.setValue(null); self.setValue(null);
data.inst.deselect_node(node);
} else { } else {
self.data('metadata', [$.extend({id: id}, $(node).getMetaData())]); self.data('metadata', $.extend({id: id}, $(node).getMetaData()));
self.setTitle(data.inst.get_text(node)); self.setTitle(data.inst.get_text(node));
self.setValue(id); self.setValue(id);
} }