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

Commit a39bc0a

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 056ab96 commit a39bc0a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/select.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@
991991
return false;
992992
};
993993
if (!inputValue) return resultMultiple; //If ngModel was undefined
994+
if ($select.tagging.isActivated) return inputValue; // If tagging is enabled, preserve model values
994995
for (var k = inputValue.length - 1; k >= 0; k--) {
995996
if (!checkFnMultiple($select.selected, inputValue[k])){
996997
checkFnMultiple(data, inputValue[k]);

test/select.spec.js

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

16691669
expect(el.scope().$select.multiple).toBe(true);
16701670
});
1671+
1672+
it('should preserve the model if tagging is enabled on select multiple', function() {
1673+
scope.selection.selectedMultiple = ["I am not on the list of choices"];
1674+
1675+
var el = compileTemplate(
1676+
'<ui-select multiple="multiple" tagging ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1677+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1678+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1679+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1680+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1681+
</ui-select-choices> \
1682+
</ui-select> \
1683+
'
1684+
);
1685+
1686+
scope.$digest();
1687+
1688+
expect(scope.selection.selectedMultiple)
1689+
.toEqual(["I am not on the list of choices"]);
1690+
});
16711691

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

0 commit comments

Comments
 (0)