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

fix(multiple): setViewValue compatible with 1.3-rc.1+ #193

Merged
merged 1 commit into from
Oct 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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{
Expand Down
26 changes: 26 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,32 @@ describe('ui-select tests', function() {

});

it('should change viewvalue only once when updating modelvalue', function () {

scope.selection.selectedMultiple = ['[email protected]', '[email protected]'];

var el = compileTemplate(
'<ui-select ng-change="onlyOnce()" multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select> \
'
);

scope.counter = 0;
scope.onlyOnce = function(){
scope.counter++;
}

clickItem(el, 'Nicole');

expect(scope.counter).toBe(1);

});

});


Expand Down