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

Commit 0c29b64

Browse files
authored
fix(uiSelectMultiple): tolerate null/undefined view value
Previously view value was checked and corrected if undefined, but then overwritten with the invalid value again. This is a minor commit to ensure the updated value isn't overwritten again. Originally authored by homerjam Closes #967 and #1686 Supersedes #1035 #1529 #1687
1 parent 4503295 commit 0c29b64

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/uiSelectMultipleDirective.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
162162
if(!angular.isArray(ngModel.$viewValue)){
163163
// Have tolerance for null or undefined values
164164
if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){
165-
$select.selected = [];
165+
ngModel.$viewValue = [];
166166
} else {
167167
throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue);
168168
}

test/select.spec.js

+37
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,43 @@ describe('ui-select tests', function() {
24942494
expect(el.scope().$select.items[1]).toEqual(jasmine.objectContaining({name: 'Amalie', email: '[email protected]'}));
24952495
});
24962496

2497+
2498+
it('should have tolerance for undefined values', function () {
2499+
2500+
scope.modelValue = undefined;
2501+
2502+
var el = compileTemplate(
2503+
'<ui-select multiple ng-model="modelValue" theme="bootstrap" style="width: 800px;"> \
2504+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
2505+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
2506+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
2507+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
2508+
</ui-select-choices> \
2509+
</ui-select> \
2510+
'
2511+
);
2512+
2513+
expect($(el).scope().$select.selected).toEqual([]);
2514+
});
2515+
2516+
it('should have tolerance for null values', function () {
2517+
2518+
scope.modelValue = null;
2519+
2520+
var el = compileTemplate(
2521+
'<ui-select multiple ng-model="modelValue" theme="bootstrap" style="width: 800px;"> \
2522+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
2523+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
2524+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
2525+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
2526+
</ui-select-choices> \
2527+
</ui-select> \
2528+
'
2529+
);
2530+
2531+
expect($(el).scope().$select.selected).toEqual([]);
2532+
});
2533+
24972534
it('should allow paste tag from clipboard', function() {
24982535
scope.taggingFunc = function (name) {
24992536
return {

0 commit comments

Comments
 (0)