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

Commit 3991091

Browse files
author
Brian Feister
committed
Merge branch 'master' of github.com:angular-ui/ui-select
2 parents d24f9bf + 0762368 commit 3991091

File tree

10 files changed

+163
-42
lines changed

10 files changed

+163
-42
lines changed

src/bootstrap/choices.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ng-show="$select.items.length > 0">
44
<li class="ui-select-choices-group">
55
<div class="divider" ng-show="$select.isGrouped && $index > 0"></div>
6-
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label dropdown-header">{{$group.name}}</div>
6+
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label dropdown-header" ng-bind-html="$group.name"></div>
77
<div class="ui-select-choices-row" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}">
88
<a href="javascript:void(0)" class="ui-select-choices-row-inner"></a>
99
</div>

src/bootstrap/match.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ng-disabled="$select.disabled"
44
ng-class="{'btn-default-focus':$select.focus}";
55
ng-click="$select.activate()">
6-
<span ng-show="$select.searchEnabled && $select.isEmpty()" class="text-muted">{{$select.placeholder}}</span>
6+
<span ng-show="$select.isEmpty()" class="text-muted">{{$select.placeholder}}</span>
77
<span ng-hide="$select.isEmpty()" ng-transclude></span>
88
<span class="caret ui-select-toggle" ng-click="$select.toggle($event)"></span>
99
</button>

src/select.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
padding-left: 0;
2929
}
3030

31+
.select2-locked > .select2-search-choice-close{
32+
display:none;
33+
}
34+
3135
/* Selectize theme */
3236

3337
/* Helper class to show styles when focus */

src/select.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function
160160
ctrl.multiple = false; // Initialized inside uiSelect directive link function
161161
ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function
162+
ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function
162163

163164
ctrl.isEmpty = function() {
164165
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
@@ -304,7 +305,13 @@
304305
};
305306

306307
ctrl.isActive = function(itemScope) {
307-
return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
308+
var isActive = ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
309+
310+
if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) {
311+
itemScope.$eval(ctrl.onHighlightCallback);
312+
}
313+
314+
return isActive;
308315
};
309316

310317
ctrl.isDisabled = function(itemScope) {
@@ -366,9 +373,24 @@
366373
e.stopPropagation();
367374
};
368375

376+
ctrl.isLocked = function(itemScope, itemIndex) {
377+
var isLocked, item = ctrl.selected[itemIndex];
378+
379+
if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) {
380+
isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value
381+
item._uiSelectChoiceLocked = isLocked; // store this for later reference
382+
}
383+
384+
return isLocked;
385+
};
386+
369387
// Remove item from multiple select
370388
ctrl.removeChoice = function(index){
371389
var removedChoice = ctrl.selected[index];
390+
391+
// if the choice is locked, can't remove it
392+
if(removedChoice._uiSelectChoiceLocked) return;
393+
372394
var locals = {};
373395
locals[ctrl.parserResult.itemName] = removedChoice;
374396

@@ -748,7 +770,7 @@
748770

749771
scope.$watch('searchEnabled', function() {
750772
var searchEnabled = scope.$eval(attrs.searchEnabled);
751-
$select.searchEnabled = searchEnabled !== undefined ? searchEnabled : true;
773+
$select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled;
752774
});
753775

754776
attrs.$observe('disabled', function() {
@@ -872,6 +894,7 @@
872894
$select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult
873895

874896
$select.disableChoiceExpression = attrs.uiDisableChoice;
897+
$select.onHighlightCallback = attrs.onHighlight;
875898

876899
if(groupByExp) {
877900
var groups = element.querySelectorAll('.ui-select-choices-group');
@@ -885,6 +908,7 @@
885908
}
886909

887910
choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp))
911+
.attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
888912
.attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
889913
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')');
890914

@@ -932,6 +956,7 @@
932956
return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
933957
},
934958
link: function(scope, element, attrs, $select) {
959+
$select.lockChoiceExpression = attrs.uiLockChoice;
935960
attrs.$observe('placeholder', function(placeholder) {
936961
$select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
937962
});

src/select2/choices.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ul class="ui-select-choices ui-select-choices-content select2-results">
22
<li class="ui-select-choices-group" ng-class="{'select2-result-with-children': $select.isGrouped}">
3-
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label select2-result-label">{{$group.name}}</div>
3+
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label select2-result-label" ng-bind-html="$group.name"></div>
44
<ul ng-class="{'select2-result-sub': $select.isGrouped, 'select2-result-single': !$select.isGrouped}">
55
<li class="ui-select-choices-row" ng-class="{'select2-highlighted': $select.isActive(this), 'select2-disabled': $select.isDisabled(this)}">
66
<div class="select2-result-label ui-select-choices-row-inner"></div>

src/select2/match-multiple.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-->
66
<span class="ui-select-match">
77
<li class="ui-select-match-item select2-search-choice" ng-repeat="$item in $select.selected"
8-
ng-class="{'select2-search-choice-focus':$select.activeMatchIndex === $index}">
8+
ng-class="{'select2-search-choice-focus':$select.activeMatchIndex === $index, 'select2-locked':$select.isLocked(this, $index)}">
99
<span uis-transclude-append></span>
1010
<a href="javascript:;" class="ui-select-match-close select2-search-choice-close" ng-click="$select.removeChoice($index)" tabindex="-1"></a>
1111
</li>

src/select2/match.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<a class="select2-choice ui-select-match"
77
ng-class="{'select2-default': $select.isEmpty()}"
88
ng-click="$select.activate()">
9-
<span ng-show="$select.searchEnabled && $select.isEmpty()" class="select2-chosen">{{$select.placeholder}}</span>
9+
<span ng-show="$select.isEmpty()" class="select2-chosen">{{$select.placeholder}}</span>
1010
<span ng-hide="$select.isEmpty()" class="select2-chosen" ng-transclude></span>
1111
<span class="select2-arrow ui-select-toggle" ng-click="$select.toggle($event)"><b></b></span>
1212
</a>

src/selectize/choices.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div ng-show="$select.open" class="ui-select-choices selectize-dropdown single">
22
<div class="ui-select-choices-content selectize-dropdown-content">
33
<div class="ui-select-choices-group optgroup">
4-
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label optgroup-header">{{$group.name}}</div>
4+
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label optgroup-header" ng-bind-html="$group.name"></div>
55
<div class="ui-select-choices-row" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}">
66
<div class="option ui-select-choices-row-inner" data-selectable></div>
77
</div>

src/selectize/match.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div ng-hide="$select.searchEnabled && ($select.open || $select.isEmpty())" class="ui-select-match" ng-transclude></div>
1+
<div ng-hide="($select.open || $select.isEmpty())" class="ui-select-match" ng-transclude></div>

0 commit comments

Comments
 (0)