Browse Source

#1753 #1368 Adds forceSelection option to force user to current search selection when element blurred

pull/1806/head
jlukic 9 years ago
parent
commit
4870dad086
1 changed files with 25 additions and 2 deletions
  1. 27
      src/definitions/modules/dropdown.js

27
src/definitions/modules/dropdown.js

@ -445,6 +445,20 @@ $.fn.dropdown = function(parameters) {
} }
}, },
forceSelection: function() {
var
$currentlySelected = $item.not(className.filtered).filter('.' + className.selected).eq(0),
$activeItem = $item.filter('.' + className.active).eq(0),
$selectedItem = ($currentlySelected.length > 0)
? $currentlySelected
: $activeItem,
hasSelected = ($selectedItem.size() > 0)
;
if(hasSelected) {
module.event.item.click.call($selectedItem);
}
},
event: { event: {
// prevents focus callback from occuring on mousedown // prevents focus callback from occuring on mousedown
mousedown: function() { mousedown: function() {
@ -475,7 +489,12 @@ $.fn.dropdown = function(parameters) {
pageLostFocus = (document.activeElement === this) pageLostFocus = (document.activeElement === this)
; ;
if(!itemActivated && !pageLostFocus) { if(!itemActivated && !pageLostFocus) {
module.hide();
if(settings.forceSelection) {
module.forceSelection();
}
else {
module.hide();
}
} }
}, },
searchTextFocus: function(event) { searchTextFocus: function(event) {
@ -687,7 +706,9 @@ $.fn.dropdown = function(parameters) {
click: function (event) { click: function (event) {
var var
$choice = $(this), $choice = $(this),
$target = $(event.target),
$target = (event)
? $(event.target)
: $(''),
$subMenu = $choice.find(selector.menu), $subMenu = $choice.find(selector.menu),
text = module.get.choiceText($choice), text = module.get.choiceText($choice),
value = module.get.choiceValue($choice, text), value = module.get.choiceValue($choice, text),
@ -1653,6 +1674,8 @@ $.fn.dropdown.settings = {
touch : 50 touch : 50
}, },
forceSelection: true,
transition : 'auto', transition : 'auto',
duration : 250, duration : 250,

Loading…
Cancel
Save