Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 5b6ac8f

Browse files
committed
Remove items from dropdown that are already selected
1 parent 07a1c51 commit 5b6ac8f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/select.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
ctrl.open = true;
140140
ctrl.activeMatchIndex = -1;
141141

142+
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
143+
142144
// Give it time to appear before focus
143145
$timeout(function() {
144146
ctrl.search = initSearchValue || ctrl.search;
@@ -198,6 +200,16 @@
198200

199201
});
200202

203+
if (ctrl.multiple){
204+
//Remove already selected items
205+
$scope.$watchCollection('$select.selected', function(selectedItems){
206+
if (!selectedItems) return;
207+
var data = ctrl.parserResult.source($scope);
208+
var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;});
209+
setItemsFn(filteredItems);
210+
});
211+
}
212+
201213
};
202214

203215
var _refreshDelayPromise;
@@ -422,7 +434,7 @@
422434
}
423435
});
424436

425-
if(~Key.verticalMovement.indexOf(key)){
437+
if(~Key.verticalMovement.indexOf(key) && ctrl.items.length > 0){
426438
_ensureHighlightVisible();
427439
}
428440

0 commit comments

Comments
 (0)