Permalink
Browse files

MINOR Unselect a selected node in TreeDropdownField (for lack of bett…

…er unselect UI)
  • Loading branch information...
1 parent 6edf055 commit e517abf2b2fcec60e369e0d35426fff68affbbcc @chillu chillu committed Jan 5, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 javascript/TreeDropdownField.js
@@ -152,21 +152,24 @@
$(this)
.jstree('destroy')
.bind('loaded.jstree', function(e, data) {
- var val = self.getValue();
- if(val) data.inst.select_node(treeHolder.find('*[data-id="' + val + '"]'));
+ var val = self.getValue(), selectNode = treeHolder.find('*[data-id="' + val + '"]'),
+ currentNode = data.inst.get_selected();
+ if(val && selectNode != currentNode) data.inst.select_node(selectNode);
data.inst.open_all();
firstLoad = false;
if(callback) callback.apply(self);
})
.jstree(self.getTreeConfig())
.bind('select_node.jstree', function(e, data) {
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.setTitle(null);
self.setValue(null);
+ data.inst.deselect_node(node);
} 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.setValue(id);
}

0 comments on commit e517abf

Please sign in to comment.