Skip to content

Commit 6f28f50

Browse files
committed
fix(ngSelect): Support static options on multi-select drop down
Removes a condition where static options are not added as part of render function when multiple attribute is enabled Closes angular#4325
1 parent 5ef8b62 commit 6f28f50

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/ng/directive/select.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
477477
selected: selected // determine if we should be selected
478478
});
479479
}
480-
if (!multiple) {
481-
if (nullOption || modelValue === null) {
482-
// insert null option if we have a placeholder, or the model is null
483-
optionGroups[''].unshift({id:'', label:'', selected:!selectedSet});
484-
} else if (!selectedSet) {
485-
// option could not be found, we have to insert the undefined item
486-
optionGroups[''].unshift({id:'?', label:'', selected:true});
487-
}
480+
if (nullOption || modelValue === null) {
481+
// insert null option if we have a placeholder, or the model is null
482+
optionGroups[''].unshift({id:'', label:'', selected:!selectedSet});
483+
} else if (!selectedSet) {
484+
// option could not be found, we have to insert the undefined item
485+
optionGroups[''].unshift({id:'?', label:'', selected:true});
488486
}
489487

490488
// Now we need to update the list of DOM nodes to match the optionGroups we computed above

test/ng/directive/selectSpec.js

+34
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,40 @@ describe('select', function() {
11481148
});
11491149

11501150

1151+
it('should include static option', function() {
1152+
createMultiSelect('<option value="">Choose One</option>');
1153+
1154+
scope.$apply(function() {
1155+
scope.values = [{name: 'A'}, {name: 'B'}];
1156+
scope.selected = [];
1157+
});
1158+
1159+
expect(element.find('option').length).toEqual(3);
1160+
expect(element.find('option')[0].selected).toBeFalsy();
1161+
expect(element.find('option')[1].selected).toBeFalsy();
1162+
expect(element.find('option')[2].selected).toBeFalsy();
1163+
1164+
scope.$apply(function() {
1165+
scope.selected.push(scope.values[0]);
1166+
});
1167+
1168+
expect(element.find('option').length).toEqual(3);
1169+
1170+
expect(element.find('option')[0].selected).toBeFalsy();
1171+
expect(element.find('option')[1].selected).toBeTruthy();
1172+
expect(element.find('option')[2].selected).toBeFalsy();
1173+
1174+
scope.$apply(function() {
1175+
scope.selected.push(scope.values[1]);
1176+
});
1177+
1178+
expect(element.find('option').length).toEqual(3);
1179+
expect(element.find('option')[0].selected).toBeFalsy();
1180+
expect(element.find('option')[1].selected).toBeTruthy();
1181+
expect(element.find('option')[2].selected).toBeTruthy();
1182+
});
1183+
1184+
11511185
it('should update model on change', function() {
11521186
createMultiSelect();
11531187

0 commit comments

Comments
 (0)