Skip to content

Commit 3b7d349

Browse files
committed
If tagging mode is activated, do not check values
Motivation: Fix angular-ui#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 bacb9d0 commit 3b7d349

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
@@ -1004,6 +1004,7 @@
10041004
return false;
10051005
};
10061006
if (!inputValue) return resultMultiple; //If ngModel was undefined
1007+
if ($select.tagging.isActivated) return inputValue; // If tagging is enabled, preserve model values
10071008
for (var k = inputValue.length - 1; k >= 0; k--) {
10081009
if (!checkFnMultiple($select.selected, inputValue[k])){
10091010
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)