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

[issue 739] Changing ng-model programmatically on multiselect. #740

Closed
wants to merge 1 commit into from
Closed
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/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
25 changes: 24 additions & 1 deletion test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<ui-select ng-model="selection.selected"> \
Expand Down Expand Up @@ -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(
'<ui-select 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.name 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>'
);

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 {
Expand Down