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

Commit 061f792

Browse files
committed
If tagging mode is activated, do not check values
Motivation: Fix #540 The tagging mode is designed to allow new values to be added to the model. It does not make sense to check those values against the list of choices when going from model --> view.
1 parent 7e390a1 commit 061f792

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/uiSelectMultipleDirective.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
102102
return false;
103103
};
104104
if (!inputValue) return resultMultiple; //If ngModel was undefined
105+
if ($select.tagging.isActivated) return inputValue; // If tagging is enabled, preserve model values
105106
for (var k = inputValue.length - 1; k >= 0; k--) {
106107
if (!checkFnMultiple($select.selected, inputValue[k])){
107108
checkFnMultiple(data, inputValue[k]);

test/select.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,26 @@ describe('ui-select tests', function() {
16861686

16871687
expect(el.scope().$select.multiple).toBe(true);
16881688
});
1689+
1690+
it('should preserve the model if tagging is enabled on select multiple', function() {
1691+
scope.selection.selectedMultiple = ["I am not on the list of choices"];
1692+
1693+
var el = compileTemplate(
1694+
'<ui-select multiple="multiple" tagging ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1695+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1696+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1697+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1698+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1699+
</ui-select-choices> \
1700+
</ui-select> \
1701+
'
1702+
);
1703+
1704+
scope.$digest();
1705+
1706+
expect(scope.selection.selectedMultiple)
1707+
.toEqual(["I am not on the list of choices"]);
1708+
});
16891709

16901710
it('should allow paste tag from clipboard', function() {
16911711
scope.taggingFunc = function (name) {

0 commit comments

Comments
 (0)