Skip to content

Commit

Permalink
patch from @dhonn
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhubbell committed Nov 24, 2014
1 parent b044b41 commit 8be220f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@
} else {
if (ctrl.multiple){
//Remove already selected items (ex: while searching)
var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;});
setItemsFn(filteredItems);
if (ctrl.selected === undefined || ctrl.selected === null) {
} else {
var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;});
setItemsFn(filteredItems);
}
}else{
setItemsFn(items);
}
Expand All @@ -264,7 +267,10 @@
if (ctrl.multiple){
//Remove already selected items
$scope.$watchCollection('$select.selected', function(selectedItems){
var data = ctrl.parserResult.source($scope);
if(selectedItems === undefined || selectedItems === null) {
return;
}
var data = ctrl.parserResult.source($scope);
if (!selectedItems.length) {
setItemsFn(data);
}else{
Expand Down Expand Up @@ -383,6 +389,7 @@
};

ctrl.getPlaceholder = function(){
if(!ctrl.selected) return;
//Refactor single?
if(ctrl.multiple && ctrl.selected.length) return;
return ctrl.placeholder;
Expand Down Expand Up @@ -768,6 +775,7 @@
ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
});
scope.$watchCollection('$select.selected', function() {
if ($select.items.length === 0) return; // If async loading prevent execution until items are not fully loaded
ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
});
focusser.prop('disabled', true); //Focusser isn't needed if multiple
Expand Down

0 comments on commit 8be220f

Please sign in to comment.