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

Commit 920b2b6

Browse files
committed
fix(multiple): setViewValue compatible with 1.3-rc.1+
1 parent 36ee169 commit 920b2b6

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/select.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@
578578
result;
579579
if ($select.multiple){
580580
var resultMultiple = [];
581-
for (var j = inputValue.length - 1; j >= 0; j--) {
581+
for (var j = $select.selected.length - 1; j >= 0; j--) {
582582
locals = {};
583-
locals[$select.parserResult.itemName] = inputValue[j];
583+
locals[$select.parserResult.itemName] = $select.selected[j];
584584
result = $select.parserResult.modelMapper(scope, locals);
585585
resultMultiple.unshift(result);
586586
}
@@ -729,10 +729,8 @@
729729
});
730730

731731
if ($select.multiple){
732-
scope.$watchCollection('$select.selected', function(newValue) {
733-
//On v1.2.19 the 2nd and 3rd parameteres are ignored
734-
//On v1.3.0-beta+ 3rd parameter (revalidate) is true, to force $parsers to recreate model
735-
ngModel.$setViewValue(newValue, null, true);
732+
scope.$watchCollection('$select.selected', function() {
733+
ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
736734
});
737735
focusser.prop('disabled', true); //Focusser isn't needed if multiple
738736
}else{

test/select.spec.js

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

13381338
});
13391339

1340+
it('should change viewvalue only once when updating modelvalue', function () {
1341+
1342+
scope.selection.selectedMultiple = ['[email protected]', '[email protected]'];
1343+
1344+
var el = compileTemplate(
1345+
'<ui-select ng-change="onlyOnce()" multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1346+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1347+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1348+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1349+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1350+
</ui-select-choices> \
1351+
</ui-select> \
1352+
'
1353+
);
1354+
1355+
scope.counter = 0;
1356+
scope.onlyOnce = function(){
1357+
scope.counter++;
1358+
}
1359+
1360+
clickItem(el, 'Nicole');
1361+
1362+
expect(scope.counter).toBe(1);
1363+
1364+
});
1365+
13401366
});
13411367

13421368

0 commit comments

Comments
 (0)