BUGFIX Allowing deselection of nodes in single select mode for TreeDropdownField (fixes #4981)

This commit is contained in:
Ingo Schommer 2011-03-10 15:35:33 +13:00
parent 2449a2b5c6
commit bde24b3415

View File

@ -3,6 +3,7 @@
var strings = { var strings = {
'openlink': 'Open', 'openlink': 'Open',
'fieldTitle': '(choose)',
'searchFieldTitle': '(choose or search)' 'searchFieldTitle': '(choose or search)'
}; };
@ -42,8 +43,10 @@
this[this.getPanel().is(':visible') ? 'closePanel' : 'openPanel'](); this[this.getPanel().is(':visible') ? 'closePanel' : 'openPanel']();
}, },
setTitle: function(title) { setTitle: function(title) {
if(!title) title = strings.fieldTitle;
this.find('.title').text(title); this.find('.title').text(title);
this.data('title', title); // separate view from storage (important for search cancellation) this.data('title', title); // separate view from storage (important for search cancellation)
}, },
getTitle: function() { getTitle: function() {
return this.find('.title').text(); return this.find('.title').text();
@ -70,9 +73,15 @@
}) })
.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; var node = data.rslt.obj, id = $(node).data('id');
self.setValue($(node).data('id')); if(self.getValue() == id) {
self.setTitle(data.inst.get_text(node)); self.setValue(null);
self.setTitle(null);
} else {
self.setValue(id);
self.setTitle(data.inst.get_text(node));
}
// Avoid auto-closing panel on first load // Avoid auto-closing panel on first load
if(!firstLoad) self.closePanel(); if(!firstLoad) self.closePanel();
}); });
@ -144,6 +153,8 @@
this.setTitle(title ? title : strings.searchFieldTitle); this.setTitle(title ? title : strings.searchFieldTitle);
}, },
setTitle: function(title) { setTitle: function(title) {
if(!title) title = strings.fieldTitle;
this.find('.title').val(title); this.find('.title').val(title);
}, },
getTitle: function() { getTitle: function() {