diff --git a/src/select.js b/src/select.js index abbdf8e22..c695bb442 100644 --- a/src/select.js +++ b/src/select.js @@ -578,9 +578,9 @@ result; if ($select.multiple){ var resultMultiple = []; - for (var j = inputValue.length - 1; j >= 0; j--) { + for (var j = $select.selected.length - 1; j >= 0; j--) { locals = {}; - locals[$select.parserResult.itemName] = inputValue[j]; + locals[$select.parserResult.itemName] = $select.selected[j]; result = $select.parserResult.modelMapper(scope, locals); resultMultiple.unshift(result); } @@ -729,10 +729,8 @@ }); if ($select.multiple){ - scope.$watchCollection('$select.selected', function(newValue) { - //On v1.2.19 the 2nd and 3rd parameteres are ignored - //On v1.3.0-beta+ 3rd parameter (revalidate) is true, to force $parsers to recreate model - ngModel.$setViewValue(newValue, null, true); + scope.$watchCollection('$select.selected', function() { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes }); focusser.prop('disabled', true); //Focusser isn't needed if multiple }else{ diff --git a/test/select.spec.js b/test/select.spec.js index f2f4f2690..72498a638 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1337,6 +1337,32 @@ describe('ui-select tests', function() { }); + it('should change viewvalue only once when updating modelvalue', function () { + + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; + + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
\ +
\ +
\ +
\ + ' + ); + + scope.counter = 0; + scope.onlyOnce = function(){ + scope.counter++; + } + + clickItem(el, 'Nicole'); + + expect(scope.counter).toBe(1); + + }); + });