Skip to content

Commit 0748465

Browse files
committed
Add test to check $setViewValue on watch (using 3rd parameter to be be compatible with v1.3.0-beta+)
1 parent 172d3ab commit 0748465

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Diff for: src/select.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,9 @@
681681

682682
if ($select.multiple){
683683
scope.$watchCollection('$select.selected', function(newValue) {
684-
ngModel.$setViewValue(newValue, null, true); //Third parameter (revalidate) is true, to force $parsers to recreate model
684+
//On v1.2.19 the 2nd and 3rd parameteres are ignored
685+
//On v1.3.0-beta+ 3rd parameter (revalidate) is true, to force $parsers to recreate model
686+
ngModel.$setViewValue(newValue, null, true);
685687
});
686688
focusser.prop('disabled', true); //Focusser isn't needed if multiple
687689
}else{

Diff for: test/select.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,35 @@ describe('ui-select tests', function() {
10771077

10781078
});
10791079

1080+
it('should watch changes for $select.selected and update formatted value correctly', function () {
1081+
1082+
scope.selection.selectedMultiple = ['[email protected]', '[email protected]'];
1083+
1084+
var el = compileTemplate(
1085+
'<ui-select multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1086+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1087+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1088+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1089+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1090+
</ui-select-choices> \
1091+
</ui-select> \
1092+
'
1093+
);
1094+
1095+
var el2 = compileTemplate('<span class="resultDiv" ng-bind="selection.selectedMultiple"></span>');
1096+
1097+
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1098+
.toBe("Wladimir <[email protected]>Samantha <[email protected]>");
1099+
1100+
clickItem(el, 'Nicole');
1101+
1102+
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1103+
.toBe("Wladimir <[email protected]>Samantha <[email protected]>Nicole <[email protected]>");
1104+
1105+
expect(scope.selection.selectedMultiple.length).toBe(3);
1106+
1107+
});
1108+
10801109
});
10811110

10821111

0 commit comments

Comments
 (0)