|
1 | 1 | /*!
|
2 | 2 | * ui-select
|
3 | 3 | * http://github.com/angular-ui/ui-select
|
4 |
| - * Version: 0.12.1 - 2015-07-28T03:50:59.076Z |
| 4 | + * Version: 0.12.1 - 2015-08-24T21:57:29.796Z |
5 | 5 | * License: MIT
|
6 | 6 | */
|
7 | 7 |
|
@@ -382,11 +382,11 @@ uis.controller('uiSelectCtrl',
|
382 | 382 | data = data || ctrl.parserResult.source($scope);
|
383 | 383 | var selectedItems = ctrl.selected;
|
384 | 384 | //TODO should implement for single mode removeSelected
|
385 |
| - if ((angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { |
| 385 | + if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { |
386 | 386 | ctrl.setItemsFn(data);
|
387 | 387 | }else{
|
388 | 388 | if ( data !== undefined ) {
|
389 |
| - var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); |
| 389 | + var filteredItems = data.filter(function(i) {return selectedItems && selectedItems.indexOf(i) < 0;}); |
390 | 390 | ctrl.setItemsFn(filteredItems);
|
391 | 391 | }
|
392 | 392 | }
|
@@ -803,6 +803,9 @@ uis.directive('uiSelect',
|
803 | 803 | $select.onSelectCallback = $parse(attrs.onSelect);
|
804 | 804 | $select.onRemoveCallback = $parse(attrs.onRemove);
|
805 | 805 |
|
| 806 | + //Limit the number of selections allowed |
| 807 | + $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; |
| 808 | + |
806 | 809 | //Set reference to ngModel from uiSelectCtrl
|
807 | 810 | $select.ngModel = ngModel;
|
808 | 811 |
|
@@ -905,8 +908,8 @@ uis.directive('uiSelect',
|
905 | 908 | if (!contains && !$select.clickTriggeredSelect) {
|
906 | 909 | //Will lose focus only with certain targets
|
907 | 910 | var focusableControls = ['input','button','textarea'];
|
908 |
| - var targetScope = angular.element(e.target).scope(); //To check if target is other ui-select |
909 |
| - var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; //To check if target is other ui-select |
| 911 | + var targetController = angular.element(e.target).controller('uiSelect'); //To check if target is other ui-select |
| 912 | + var skipFocusser = targetController && targetController !== $select; //To check if target is other ui-select |
910 | 913 | if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea
|
911 | 914 | $select.close(skipFocusser);
|
912 | 915 | scope.$digest();
|
@@ -1029,7 +1032,7 @@ uis.directive('uiSelect',
|
1029 | 1032 | var offsetDropdown = uisOffset(dropdown);
|
1030 | 1033 |
|
1031 | 1034 | // Determine if the direction of the dropdown needs to be changed.
|
1032 |
| - if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { |
| 1035 | + if (offset.top + offset.height + offsetDropdown.height > $document.scrollTop() + $document[0].documentElement.clientHeight) { |
1033 | 1036 | dropdown[0].style.position = 'absolute';
|
1034 | 1037 | dropdown[0].style.top = (offsetDropdown.height * -1) + 'px';
|
1035 | 1038 | element.addClass(directionUpClassName);
|
@@ -1145,7 +1148,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
|
1145 | 1148 |
|
1146 | 1149 | ctrl.getPlaceholder = function(){
|
1147 | 1150 | //Refactor single?
|
1148 |
| - if($select.selected.length) return; |
| 1151 | + if($select.selected && $select.selected.length) return; |
1149 | 1152 | return $select.placeholder;
|
1150 | 1153 | };
|
1151 | 1154 |
|
@@ -1244,6 +1247,9 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
|
1244 | 1247 | };
|
1245 | 1248 |
|
1246 | 1249 | scope.$on('uis:select', function (event, item) {
|
| 1250 | + if($select.selected.length >= $select.limit) { |
| 1251 | + return; |
| 1252 | + } |
1247 | 1253 | $select.selected.push(item);
|
1248 | 1254 | $selectMultiple.updateModel();
|
1249 | 1255 | });
|
@@ -1488,6 +1494,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
|
1488 | 1494 | }
|
1489 | 1495 | };
|
1490 | 1496 | }]);
|
| 1497 | + |
1491 | 1498 | uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) {
|
1492 | 1499 | return {
|
1493 | 1500 | restrict: 'EA',
|
|
0 commit comments