From bde24b34158d0259a143aefb5f73fda206fa5107 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 10 Mar 2011 15:35:33 +1300 Subject: [PATCH] BUGFIX Allowing deselection of nodes in single select mode for TreeDropdownField (fixes #4981) --- javascript/TreeDropdownField.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/javascript/TreeDropdownField.js b/javascript/TreeDropdownField.js index 91460f99e..ac0494012 100644 --- a/javascript/TreeDropdownField.js +++ b/javascript/TreeDropdownField.js @@ -3,6 +3,7 @@ var strings = { 'openlink': 'Open', + 'fieldTitle': '(choose)', 'searchFieldTitle': '(choose or search)' }; @@ -42,8 +43,10 @@ this[this.getPanel().is(':visible') ? 'closePanel' : 'openPanel'](); }, setTitle: function(title) { + if(!title) title = strings.fieldTitle; + 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() { return this.find('.title').text(); @@ -70,9 +73,15 @@ }) .jstree(self.getTreeConfig()) .bind('select_node.jstree', function(e, data) { - var node = data.rslt.obj; - self.setValue($(node).data('id')); - self.setTitle(data.inst.get_text(node)); + var node = data.rslt.obj, id = $(node).data('id'); + if(self.getValue() == id) { + self.setValue(null); + self.setTitle(null); + } else { + self.setValue(id); + self.setTitle(data.inst.get_text(node)); + } + // Avoid auto-closing panel on first load if(!firstLoad) self.closePanel(); }); @@ -144,6 +153,8 @@ this.setTitle(title ? title : strings.searchFieldTitle); }, setTitle: function(title) { + if(!title) title = strings.fieldTitle; + this.find('.title').val(title); }, getTitle: function() {