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

Commit 5b7d958

Browse files
committed
Remove items from dropdown that are already selected
1 parent 40cd450 commit 5b7d958

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
@@ -141,6 +141,8 @@
141141
ctrl.open = true;
142142
ctrl.activeMatchIndex = -1;
143143

144+
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
145+
144146
// Give it time to appear before focus
145147
$timeout(function() {
146148
ctrl.search = initSearchValue || ctrl.search;
@@ -200,6 +202,16 @@
200202

201203
});
202204

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

205217
var _refreshDelayPromise;
@@ -424,7 +436,7 @@
424436
}
425437
});
426438

427-
if(~Key.verticalMovement.indexOf(key)){
439+
if(~Key.verticalMovement.indexOf(key) && ctrl.items.length > 0){
428440
_ensureHighlightVisible();
429441
}
430442

0 commit comments

Comments
 (0)