Skip to content

Commit

Permalink
Merge pull request angular-ui#321 from phxdatasec/feat-lock
Browse files Browse the repository at this point in the history
angular-ui#319 fix for lock selections
  • Loading branch information
amcdnl committed Nov 14, 2014
2 parents e277a1c + a5b66d7 commit 3be92eb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/select.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
padding-left: 0;
}

.select2-locked > .select2-search-choice-close{
display:none;
}

/* Selectize theme */

/* Helper class to show styles when focus */
Expand Down
17 changes: 17 additions & 0 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function
ctrl.multiple = false; // Initialized inside uiSelect directive link function
ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function
ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function

ctrl.isEmpty = function() {
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
Expand Down Expand Up @@ -366,9 +367,24 @@
e.stopPropagation();
};

ctrl.isLocked = function(itemScope, itemIndex) {
var isLocked, item = ctrl.selected[itemIndex];

if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) {
isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value
item._uiSelectChoiceLocked = isLocked; // store this for later reference
}

return isLocked;
};

// Remove item from multiple select
ctrl.removeChoice = function(index){
var removedChoice = ctrl.selected[index];

// if the choice is locked, can't remove it
if(removedChoice._uiSelectChoiceLocked) return;

var locals = {};
locals[ctrl.parserResult.itemName] = removedChoice;

Expand Down Expand Up @@ -933,6 +949,7 @@
return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
},
link: function(scope, element, attrs, $select) {
$select.lockChoiceExpression = attrs.uiLockChoice;
attrs.$observe('placeholder', function(placeholder) {
$select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
});
Expand Down
2 changes: 1 addition & 1 deletion src/select2/match-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-->
<span class="ui-select-match">
<li class="ui-select-match-item select2-search-choice" ng-repeat="$item in $select.selected"
ng-class="{'select2-search-choice-focus':$select.activeMatchIndex === $index}">
ng-class="{'select2-search-choice-focus':$select.activeMatchIndex === $index, 'select2-locked':$select.isLocked(this, $index)}">
<span uis-transclude-append></span>
<a href="javascript:;" class="ui-select-match-close select2-search-choice-close" ng-click="$select.removeChoice($index)" tabindex="-1"></a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('ui-select tests', function() {
expect(isDropdownOpened(el2)).toEqual(true);

var el3 = createUiSelect();
expect(el3.scope().$select.disabled).toEqual(false);
expect(el3.scope().$select.disabled).toEqual(false || undefined);
clickMatch(el3);
expect(isDropdownOpened(el3)).toEqual(true);
});
Expand Down

0 comments on commit 3be92eb

Please sign in to comment.