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

Commit 3be92eb

Browse files
committed
Merge pull request #321 from phxdatasec/feat-lock
#319 fix for lock selections
2 parents e277a1c + a5b66d7 commit 3be92eb

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

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: 17 additions & 0 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 === '';
@@ -366,9 +367,24 @@
366367
e.stopPropagation();
367368
};
368369

370+
ctrl.isLocked = function(itemScope, itemIndex) {
371+
var isLocked, item = ctrl.selected[itemIndex];
372+
373+
if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) {
374+
isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value
375+
item._uiSelectChoiceLocked = isLocked; // store this for later reference
376+
}
377+
378+
return isLocked;
379+
};
380+
369381
// Remove item from multiple select
370382
ctrl.removeChoice = function(index){
371383
var removedChoice = ctrl.selected[index];
384+
385+
// if the choice is locked, can't remove it
386+
if(removedChoice._uiSelectChoiceLocked) return;
387+
372388
var locals = {};
373389
locals[ctrl.parserResult.itemName] = removedChoice;
374390

@@ -933,6 +949,7 @@
933949
return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
934950
},
935951
link: function(scope, element, attrs, $select) {
952+
$select.lockChoiceExpression = attrs.uiLockChoice;
936953
attrs.$observe('placeholder', function(placeholder) {
937954
$select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
938955
});

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>

test/select.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ describe('ui-select tests', function() {
255255
expect(isDropdownOpened(el2)).toEqual(true);
256256

257257
var el3 = createUiSelect();
258-
expect(el3.scope().$select.disabled).toEqual(false);
258+
expect(el3.scope().$select.disabled).toEqual(false || undefined);
259259
clickMatch(el3);
260260
expect(isDropdownOpened(el3)).toEqual(true);
261261
});

0 commit comments

Comments
 (0)