|
138 | 138 | * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
|
139 | 139 | */
|
140 | 140 | .controller('uiSelectCtrl',
|
141 |
| - ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', |
142 |
| - function($scope, $element, $timeout, RepeatParser, uiSelectMinErr) { |
| 141 | + ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', 'uiSelectConfig', |
| 142 | + function($scope, $element, $timeout, RepeatParser, uiSelectMinErr, uiSelectConfig) { |
143 | 143 |
|
144 | 144 | var ctrl = this;
|
145 | 145 |
|
|
160 | 160 | ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function
|
161 | 161 | ctrl.multiple = false; // Initialized inside uiSelect directive link function
|
162 | 162 | ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function
|
| 163 | + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function |
163 | 164 | ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function
|
164 | 165 | ctrl.clickTriggeredSelect = false;
|
165 | 166 |
|
|
174 | 175 |
|
175 | 176 | // Most of the time the user does not want to empty the search input when in typeahead mode
|
176 | 177 | function _resetSearchInput() {
|
177 |
| - if (ctrl.resetSearchInput) { |
| 178 | + if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { |
178 | 179 | ctrl.search = EMPTY_SEARCH;
|
179 | 180 | //reset activeIndex
|
180 | 181 | if (ctrl.selected && ctrl.items.length && !ctrl.multiple) {
|
|
307 | 308 | };
|
308 | 309 |
|
309 | 310 | ctrl.isActive = function(itemScope) {
|
310 |
| - return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; |
| 311 | + var isActive = ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; |
| 312 | + |
| 313 | + if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { |
| 314 | + itemScope.$eval(ctrl.onHighlightCallback); |
| 315 | + } |
| 316 | + |
| 317 | + return isActive; |
311 | 318 | };
|
312 | 319 |
|
313 | 320 | ctrl.isDisabled = function(itemScope) {
|
|
373 | 380 | e.stopPropagation();
|
374 | 381 | };
|
375 | 382 |
|
| 383 | + ctrl.isLocked = function(itemScope, itemIndex) { |
| 384 | + var isLocked, item = ctrl.selected[itemIndex]; |
| 385 | + |
| 386 | + if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { |
| 387 | + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value |
| 388 | + item._uiSelectChoiceLocked = isLocked; // store this for later reference |
| 389 | + } |
| 390 | + |
| 391 | + return isLocked; |
| 392 | + }; |
| 393 | + |
376 | 394 | // Remove item from multiple select
|
377 | 395 | ctrl.removeChoice = function(index){
|
378 | 396 | var removedChoice = ctrl.selected[index];
|
| 397 | + |
| 398 | + // if the choice is locked, can't remove it |
| 399 | + if(removedChoice._uiSelectChoiceLocked) return; |
| 400 | + |
379 | 401 | var locals = {};
|
380 | 402 | locals[ctrl.parserResult.itemName] = removedChoice;
|
381 | 403 |
|
|
880 | 902 | $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult
|
881 | 903 |
|
882 | 904 | $select.disableChoiceExpression = attrs.uiDisableChoice;
|
| 905 | + $select.onHighlightCallback = attrs.onHighlight; |
883 | 906 |
|
884 | 907 | if(groupByExp) {
|
885 | 908 | var groups = element.querySelectorAll('.ui-select-choices-group');
|
|
941 | 964 | return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
|
942 | 965 | },
|
943 | 966 | link: function(scope, element, attrs, $select) {
|
| 967 | + $select.lockChoiceExpression = attrs.uiLockChoice; |
944 | 968 | attrs.$observe('placeholder', function(placeholder) {
|
945 | 969 | $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
|
946 | 970 | });
|
|
0 commit comments