Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MINOR Close open TreeDropdownField panels if user clicks outside of t…

…he field (emulate behaviour of chosen.js and most native OS dropdowns)
  • Loading branch information...
commit 66a60476ac968f7349cc0d44eb62c1a61b7fb2ab 1 parent c0c073e
@chillu chillu authored
Showing with 11 additions and 1 deletion.
  1. +11 −1 javascript/TreeDropdownField.js
View
12 javascript/TreeDropdownField.js
@@ -13,7 +13,12 @@
'fieldTitle': '(choose)',
'searchFieldTitle': '(choose or search)'
};
-
+
+ var _clickTestFn = function(e) {
+ // If the click target is not a child of the current field, close the panel automatically.
+ if(!$(e.target).parents('.TreeDropdownField').length) jQuery('.TreeDropdownField').entwine('ss').closePanel();
+ };
+
/**
* @todo Error display
* @todo No results display for search
@@ -45,6 +50,9 @@
openPanel: function() {
// close all other panels
$('.TreeDropdownField').closePanel();
+
+ // Listen for clicks outside of the field to auto-close it
+ $('body').bind('click', _clickTestFn);
var panel = this.getPanel(), tree = this.find('.tree-holder');
@@ -80,6 +88,8 @@
},
closePanel: function() {
+ jQuery('body').unbind('click', _clickTestFn);
+
// swap the up arrow with a down arrow
var toggle = this.find(".treedropdownfield-toggle-panel-link");
toggle.removeClass('treedropdownfield-open-tree');
Please sign in to comment.
Something went wrong with that request. Please try again.