Skip to content

Commit 9c18723

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 7c38698 commit 9c18723

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
@@ -1002,6 +1002,7 @@
10021002
return false;
10031003
};
10041004
if (!inputValue) return resultMultiple; //If ngModel was undefined
1005+
if ($select.tagging.isActivated) return inputValue; // If tagging is enabled, preserve model values
10051006
for (var k = inputValue.length - 1; k >= 0; k--) {
10061007
if (!checkFnMultiple($select.selected, inputValue[k])){
10071008
checkFnMultiple(data, inputValue[k]);

test/select.spec.js

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

16541654
expect(el.scope().$select.multiple).toBe(true);
16551655
});
1656+
1657+
it('should preserve the model if tagging is enabled on select multiple', function() {
1658+
scope.selection.selectedMultiple = ["I am not on the list of choices"];
1659+
1660+
var el = compileTemplate(
1661+
'<ui-select multiple="multiple" tagging ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1662+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1663+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1664+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1665+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1666+
</ui-select-choices> \
1667+
</ui-select> \
1668+
'
1669+
);
1670+
1671+
scope.$digest();
1672+
1673+
expect(scope.selection.selectedMultiple)
1674+
.toEqual(["I am not on the list of choices"]);
1675+
});
16561676

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

0 commit comments

Comments
 (0)