11/*!
22 * ui-select
33 * http://github.com/angular-ui/ui-select
4- * Version: 0.18.0 - 2016-07-04T12:25:46.142Z
4+ * Version: 0.18.1 - 2016-07-10T00:30:49.391Z
55 * License: MIT
66 */
77
@@ -589,18 +589,44 @@ uis.controller('uiSelectCtrl',
589589 ctrl . selected . filter ( function ( selection ) { return angular . equals ( selection , item ) ; } ) . length > 0 ) ;
590590 } ;
591591
592+ var disabledItems = [ ] ;
593+
594+ function _updateItemDisabled ( item , isDisabled ) {
595+ var disabledItemIndex = disabledItems . indexOf ( item ) ;
596+ if ( isDisabled && disabledItemIndex === - 1 ) {
597+ disabledItems . push ( item ) ;
598+ }
599+
600+ if ( ! isDisabled && disabledItemIndex > - 1 ) {
601+ disabledItems . splice ( disabledItemIndex , 0 ) ;
602+ }
603+ }
604+
605+ function _isItemDisabled ( item ) {
606+ return disabledItems . indexOf ( item ) > - 1 ;
607+ }
608+
592609 ctrl . isDisabled = function ( itemScope ) {
593610
594611 if ( ! ctrl . open ) return ;
595612
596- var itemIndex = ctrl . items . indexOf ( itemScope [ ctrl . itemProperty ] ) ;
613+ var item = itemScope [ ctrl . itemProperty ] ;
614+ var itemIndex = ctrl . items . indexOf ( item ) ;
597615 var isDisabled = false ;
598- var item ;
616+
617+ if ( itemIndex >= 0 && ( angular . isDefined ( ctrl . disableChoiceExpression ) || ctrl . multiple ) ) {
618+
619+ if ( item . isTag ) return false ;
620+
621+ if ( ctrl . multiple ) {
622+ isDisabled = _isItemSelected ( item ) ;
623+ }
599624
600- if ( itemIndex >= 0 && ( ! angular . isUndefined ( ctrl . disableChoiceExpression ) || ctrl . multiple ) ) {
601- item = ctrl . items [ itemIndex ] ;
602- isDisabled = ! ! ( itemScope . $eval ( ctrl . disableChoiceExpression ) ) || _isItemSelected ( item ) ; // force the boolean value
603- item . _uiSelectChoiceDisabled = isDisabled ; // store this for later reference
625+ if ( ! isDisabled && angular . isDefined ( ctrl . disableChoiceExpression ) ) {
626+ isDisabled = ! ! ( itemScope . $eval ( ctrl . disableChoiceExpression ) ) ;
627+ }
628+
629+ _updateItemDisabled ( item , isDisabled ) ;
604630 }
605631
606632 return isDisabled ;
@@ -609,11 +635,11 @@ uis.controller('uiSelectCtrl',
609635
610636 // When the user selects an item with ENTER or clicks the dropdown
611637 ctrl . select = function ( item , skipFocusser , $event ) {
612- if ( item === undefined || ! item . _uiSelectChoiceDisabled ) {
638+ if ( item === undefined || ! _isItemDisabled ( item ) ) {
613639
614640 if ( ! ctrl . items && ! ctrl . search && ! ctrl . tagging . isActivated ) return ;
615641
616- if ( ! item || ! item . _uiSelectChoiceDisabled ) {
642+ if ( ! item || ! _isItemDisabled ( item ) ) {
617643 if ( ctrl . tagging . isActivated ) {
618644 // if taggingLabel is disabled and item is undefined we pull from ctrl.search
619645 if ( ctrl . taggingLabel === false ) {
@@ -711,16 +737,53 @@ uis.controller('uiSelectCtrl',
711737 }
712738 } ;
713739
714- ctrl . isLocked = function ( itemScope , itemIndex ) {
715- var isLocked , item = ctrl . selected [ itemIndex ] ;
740+ // Set default function for locked choices - avoids unnecessary
741+ // logic if functionality is not being used
742+ ctrl . isLocked = function ( ) {
743+ return false ;
744+ } ;
745+
746+ $scope . $watch ( function ( ) {
747+ return angular . isDefined ( ctrl . lockChoiceExpression ) && ctrl . lockChoiceExpression !== "" ;
748+ } , _initaliseLockedChoices ) ;
716749
717- if ( item && ! angular . isUndefined ( ctrl . lockChoiceExpression ) ) {
718- isLocked = ! ! ( itemScope . $eval ( ctrl . lockChoiceExpression ) ) ; // force the boolean value
719- item . _uiSelectChoiceLocked = isLocked ; // store this for later reference
750+ function _initaliseLockedChoices ( doInitalise ) {
751+ if ( ! doInitalise ) return ;
752+
753+ var lockedItems = [ ] ;
754+
755+ function _updateItemLocked ( item , isLocked ) {
756+ var lockedItemIndex = lockedItems . indexOf ( item ) ;
757+ if ( isLocked && lockedItemIndex === - 1 ) {
758+ lockedItems . push ( item ) ;
759+ }
760+
761+ if ( ! isLocked && lockedItemIndex > - 1 ) {
762+ lockedItems . splice ( lockedItemIndex , 0 ) ;
763+ }
764+ }
765+
766+ function _isItemlocked ( item ) {
767+ return lockedItems . indexOf ( item ) > - 1 ;
768+ }
769+
770+ ctrl . isLocked = function ( itemScope , itemIndex ) {
771+ var isLocked = false ,
772+ item = ctrl . selected [ itemIndex ] ;
773+
774+ if ( item ) {
775+ if ( itemScope ) {
776+ isLocked = ! ! ( itemScope . $eval ( ctrl . lockChoiceExpression ) ) ;
777+ _updateItemLocked ( item , isLocked ) ;
778+ } else {
779+ isLocked = _isItemlocked ( item ) ;
780+ }
720781 }
721782
722783 return isLocked ;
723- } ;
784+ } ;
785+ }
786+
724787
725788 var sizeWatch = null ;
726789 var updaterScheduled = false ;
@@ -1012,16 +1075,15 @@ uis.directive('uiSelect',
10121075 } ) ;
10131076 }
10141077
1015- scope . $watch ( 'searchEnabled' , function ( ) {
1016- var searchEnabled = scope . $eval ( attrs . searchEnabled ) ;
1017- $select . searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig . searchEnabled ;
1078+ scope . $watch ( function ( ) { return scope . $eval ( attrs . searchEnabled ) ; } , function ( newVal ) {
1079+ $select . searchEnabled = newVal !== undefined ? newVal : uiSelectConfig . searchEnabled ;
10181080 } ) ;
10191081
10201082 scope . $watch ( 'sortable' , function ( ) {
10211083 var sortable = scope . $eval ( attrs . sortable ) ;
10221084 $select . sortable = sortable !== undefined ? sortable : uiSelectConfig . sortable ;
10231085 } ) ;
1024-
1086+
10251087 attrs . $observe ( 'limit' , function ( ) {
10261088 //Limit the number of selections allowed
10271089 $select . limit = ( angular . isDefined ( attrs . limit ) ) ? parseInt ( attrs . limit , 10 ) : undefined ;
@@ -1416,17 +1478,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
14161478 //Remove already selected items
14171479 //e.g. When user clicks on a selection, the selected array changes and
14181480 //the dropdown should remove that item
1419- $select . refreshItems ( ) ;
1420- $select . sizeSearchInput ( ) ;
1481+ if ( $select . refreshItems ) {
1482+ $select . refreshItems ( ) ;
1483+ }
1484+ if ( $select . sizeSearchInput ) {
1485+ $select . sizeSearchInput ( ) ;
1486+ }
14211487 } ;
14221488
14231489 // Remove item from multiple select
14241490 ctrl . removeChoice = function ( index ) {
14251491
1426- var removedChoice = $select . selected [ index ] ;
1492+ // if the choice is locked, don't remove it
1493+ if ( $select . isLocked ( null , index ) ) return false ;
14271494
1428- // if the choice is locked, can't remove it
1429- if ( removedChoice . _uiSelectChoiceLocked ) return ;
1495+ var removedChoice = $select . selected [ index ] ;
14301496
14311497 var locals = { } ;
14321498 locals [ $select . parserResult . itemName ] = removedChoice ;
@@ -1445,6 +1511,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
14451511
14461512 ctrl . updateModel ( ) ;
14471513
1514+ return true ;
14481515 } ;
14491516
14501517 ctrl . getPlaceholder = function ( ) {
@@ -1548,7 +1615,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
15481615 if ( ! angular . isArray ( ngModel . $viewValue ) ) {
15491616 // Have tolerance for null or undefined values
15501617 if ( angular . isUndefined ( ngModel . $viewValue ) || ngModel . $viewValue === null ) {
1551- $select . selected = [ ] ;
1618+ ngModel . $viewValue = [ ] ;
15521619 } else {
15531620 throw uiSelectMinErr ( 'multiarr' , "Expected model value to be array but got '{0}'" , ngModel . $viewValue ) ;
15541621 }
@@ -1632,11 +1699,16 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
16321699 case KEY . BACKSPACE :
16331700 // Remove selected item and select previous/first
16341701 if ( ~ $selectMultiple . activeMatchIndex ) {
1635- $selectMultiple . removeChoice ( curr ) ;
1636- return prev ;
1637- }
1638- // Select last item
1639- else return last ;
1702+ if ( $selectMultiple . removeChoice ( curr ) ) {
1703+ return prev ;
1704+ } else {
1705+ return curr ;
1706+ }
1707+
1708+ } else {
1709+ // If nothing yet selected, select last item
1710+ return last ;
1711+ }
16401712 break ;
16411713 case KEY . DELETE :
16421714 // Remove selected item and select next item
@@ -2241,9 +2313,10 @@ $templateCache.put("bootstrap/select.tpl.html","<div class=\"ui-select-container
22412313$templateCache . put ( "select2/choices.tpl.html" , "<ul tabindex=\"-1\" class=\"ui-select-choices ui-select-choices-content select2-results\"><li class=\"ui-select-choices-group\" ng-class=\"{\'select2-result-with-children\': $select.choiceGrouped($group) }\"><div ng-show=\"$select.choiceGrouped($group)\" class=\"ui-select-choices-group-label select2-result-label\" ng-bind=\"$group.name\"></div><ul role=\"listbox\" id=\"ui-select-choices-{{ $select.generatedId }}\" ng-class=\"{\'select2-result-sub\': $select.choiceGrouped($group), \'select2-result-single\': !$select.choiceGrouped($group) }\"><li role=\"option\" ng-attr-id=\"ui-select-choices-row-{{ $select.generatedId }}-{{$index}}\" class=\"ui-select-choices-row\" ng-class=\"{\'select2-highlighted\': $select.isActive(this), \'select2-disabled\': $select.isDisabled(this)}\"><div class=\"select2-result-label ui-select-choices-row-inner\"></div></li></ul></li></ul>" ) ;
22422314$templateCache . put ( "select2/match-multiple.tpl.html" , "<span class=\"ui-select-match\"><li class=\"ui-select-match-item select2-search-choice\" ng-repeat=\"$item in $select.selected track by $index\" ng-class=\"{\'select2-search-choice-focus\':$selectMultiple.activeMatchIndex === $index, \'select2-locked\':$select.isLocked(this, $index)}\" ui-select-sort=\"$select.selected\"><span uis-transclude-append=\"\"></span> <a href=\"javascript:;\" class=\"ui-select-match-close select2-search-choice-close\" ng-click=\"$selectMultiple.removeChoice($index)\" tabindex=\"-1\"></a></li></span>" ) ;
22432315$templateCache . put ( "select2/match.tpl.html" , "<a class=\"select2-choice ui-select-match\" ng-class=\"{\'select2-default\': $select.isEmpty()}\" ng-click=\"$select.toggle($event)\" aria-label=\"{{ $select.baseTitle }} select\"><span ng-show=\"$select.isEmpty()\" class=\"select2-chosen\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" class=\"select2-chosen\" ng-transclude=\"\"></span> <abbr ng-if=\"$select.allowClear && !$select.isEmpty()\" class=\"select2-search-choice-close\" ng-click=\"$select.clear($event)\"></abbr> <span class=\"select2-arrow ui-select-toggle\"><b></b></span></a>" ) ;
2316+ $templateCache . put ( "select2/no-choice.tpl.html" , "<div class=\"ui-select-no-choice dropdown\" ng-show=\"$select.items.length == 0\"><div class=\"dropdown-content\"><div data-selectable=\"\" ng-transclude=\"\"></div></div></div>" ) ;
22442317$templateCache . put ( "select2/select-multiple.tpl.html" , "<div class=\"ui-select-container ui-select-multiple select2 select2-container select2-container-multi\" ng-class=\"{\'select2-container-active select2-dropdown-open open\': $select.open, \'select2-container-disabled\': $select.disabled}\"><ul class=\"select2-choices\"><span class=\"ui-select-match\"></span><li class=\"select2-search-field\"><input type=\"search\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" role=\"combobox\" aria-expanded=\"true\" aria-owns=\"ui-select-choices-{{ $select.generatedId }}\" aria-label=\"{{ $select.baseTitle }}\" aria-activedescendant=\"ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}\" class=\"select2-input ui-select-search\" placeholder=\"{{$selectMultiple.getPlaceholder()}}\" ng-disabled=\"$select.disabled\" ng-hide=\"$select.disabled\" ng-model=\"$select.search\" ng-click=\"$select.activate()\" style=\"width: 34px;\" ondrop=\"return false;\"></li></ul><div class=\"ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open || $select.items.length === 0}\"><div class=\"ui-select-choices\"></div></div></div>" ) ;
2245- $templateCache . put ( "select2/select.tpl.html" , "<div class=\"ui-select-container select2 select2-container\" ng-class=\"{\'select2-container-active select2-dropdown-open open\': $select.open, \'select2-container-disabled\': $select.disabled, \'select2-container-active\': $select.focus, \'select2-allowclear\': $select.allowClear && !$select.isEmpty()}\"><div class=\"ui-select-match\"></div><div class=\"ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"select2-search\" ng-show=\"$select.searchEnabled\"><input type=\"search\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" role=\"combobox\" aria-expanded=\"true\" aria-owns=\"ui-select-choices-{{ $select.generatedId }}\" aria-label=\"{{ $select.baseTitle }}\" aria-activedescendant=\"ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}\" class=\"ui-select-search select2-input\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div></div></div>" ) ;
2318+ $templateCache . put ( "select2/select.tpl.html" , "<div class=\"ui-select-container select2 select2-container\" ng-class=\"{\'select2-container-active select2-dropdown-open open\': $select.open, \'select2-container-disabled\': $select.disabled, \'select2-container-active\': $select.focus, \'select2-allowclear\': $select.allowClear && !$select.isEmpty()}\"><div class=\"ui-select-match\"></div><div class=\"ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"select2-search\" ng-show=\"$select.searchEnabled\"><input type=\"search\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" role=\"combobox\" aria-expanded=\"true\" aria-owns=\"ui-select-choices-{{ $select.generatedId }}\" aria-label=\"{{ $select.baseTitle }}\" aria-activedescendant=\"ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}\" class=\"ui-select-search select2-input\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div></div>" ) ;
22462319$templateCache . put ( "selectize/choices.tpl.html" , "<div ng-show=\"$select.open\" class=\"ui-select-choices ui-select-dropdown selectize-dropdown single\"><div class=\"ui-select-choices-content selectize-dropdown-content\"><div class=\"ui-select-choices-group optgroup\" role=\"listbox\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label optgroup-header\" ng-bind=\"$group.name\"></div><div role=\"option\" class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this), disabled: $select.isDisabled(this)}\"><div class=\"option ui-select-choices-row-inner\" data-selectable=\"\"></div></div></div></div></div>" ) ;
22472320$templateCache . put ( "selectize/match.tpl.html" , "<div ng-hide=\"$select.searchEnabled && ($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>" ) ;
22482321$templateCache . put ( "selectize/no-choice.tpl.html" , "<div class=\"ui-select-no-choice selectize-dropdown\" ng-show=\"$select.items.length == 0\"><div class=\"selectize-dropdown-content\"><div data-selectable=\"\" ng-transclude=\"\"></div></div></div>" ) ;
2249- $templateCache . put ( "selectize/select.tpl.html" , "<div class=\"ui-select-container selectize-control single\" ng-class=\"{\'open\': $select.open}\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.open && !$select.searchEnabled ? $select.toggle($event) : $select.activate()\"><div class=\"ui-select-match\"></div><input type=\"search\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\" aria-label=\"{{ $select.baseTitle }}\"></div><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div>" ) ; } ] ) ;
2322+ $templateCache . put ( "selectize/select.tpl.html" , "<div class=\"ui-select-container selectize-control single\" ng-class=\"{\'open\': $select.open}\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.open && !$select.searchEnabled ? $select.toggle($event) : $select.activate()\"><div class=\"ui-select-match\"></div><input type=\"search\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || (! $select.isEmpty() && !$select.open)\" ng-disabled=\"$select.disabled\" aria-label=\"{{ $select.baseTitle }}\"></div><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div>" ) ; } ] ) ;
0 commit comments