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

fix(uiSelectMultiple): tolerate null/undefined model value #1709

Merged
merged 1 commit into from
Jul 7, 2016
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
2 changes: 1 addition & 1 deletion src/uiSelectMultipleDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
if(!angular.isArray(ngModel.$viewValue)){
// Have tolerance for null or undefined values
if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){
$select.selected = [];
ngModel.$viewValue = [];
} else {
throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue);
}
Expand Down
37 changes: 37 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,43 @@ describe('ui-select tests', function() {
expect(el.scope().$select.items[1]).toEqual(jasmine.objectContaining({name: 'Amalie', email: '[email protected]'}));
});


it('should have tolerance for undefined values', function () {

scope.modelValue = undefined;

var el = compileTemplate(
'<ui-select multiple ng-model="modelValue" 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> \
'
);

expect($(el).scope().$select.selected).toEqual([]);
});

it('should have tolerance for null values', function () {

scope.modelValue = null;

var el = compileTemplate(
'<ui-select multiple ng-model="modelValue" 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> \
'
);

expect($(el).scope().$select.selected).toEqual([]);
});

it('should allow paste tag from clipboard', function() {
scope.taggingFunc = function (name) {
return {
Expand Down