diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 00fe1aa28..fc2df8846 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -97,7 +97,7 @@ uis.directive('uiSelect', }; if (!inputValue) return resultMultiple; //If ngModel was undefined for (var k = inputValue.length - 1; k >= 0; k--) { - if (!checkFnMultiple($select.selected, inputValue[k])){ + if (!$select.selected || !$select.selected.length || !checkFnMultiple($select.selected, inputValue[k])){ checkFnMultiple(data, inputValue[k]); } } diff --git a/test/select.spec.js b/test/select.spec.js index 8be66afa8..f5481cfac 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -191,7 +191,7 @@ describe('ui-select tests', function() { expect(getMatchLabel(el)).toEqual('Adam'); }); - + it('should correctly render initial state with track by feature', function() { var el = compileTemplate( ' \ @@ -1669,6 +1669,29 @@ describe('ui-select tests', function() { expect(el.scope().$select.multiple).toBe(true); }); + it('should properly format values set on model for complex models', function() { + + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
\ +
\ +
\ +
' + ); + + var searchInput = el.find('.ui-select-search'); + + scope.selection.selectedMultiple = ['Estefanía', 'Adrian']; + + // there was issue after second digest cyle, so we are triggering it twice + el.scope().$digest(); + el.scope().$digest(); + + expect(el.scope().$select.selected).toEqual([scope.people[2], scope.people[3]]); + }); + it('should allow paste tag from clipboard', function() { scope.taggingFunc = function (name) { return {