Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 26adeb1

Browse files
_pantsIgorMinar
_pants
authored andcommitted
fix(select): support optgroup + select[multiple] combo
Closes #1553
1 parent 15183f3 commit 26adeb1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/ng/directive/select.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
265265
var lastView;
266266
ctrl.$render = function() {
267267
var items = new HashMap(ctrl.$viewValue);
268-
forEach(selectElement.children(), function(option) {
268+
forEach(selectElement.find('option'), function(option) {
269269
option.selected = isDefined(items.get(option.value));
270270
});
271271
};
@@ -282,7 +282,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
282282
selectElement.bind('change', function() {
283283
scope.$apply(function() {
284284
var array = [];
285-
forEach(selectElement.children(), function(option) {
285+
forEach(selectElement.find('option'), function(option) {
286286
if (option.selected) {
287287
array.push(option.value);
288288
}

test/ng/directive/selectSpec.js

+21
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,27 @@ describe('select', function() {
405405
expect(element).toEqualSelect(['A'], ['B']);
406406
});
407407

408+
it('should work with optgroups', function() {
409+
compile('<select ng-model="selection" multiple>' +
410+
'<optgroup label="group1">' +
411+
'<option>A</option>' +
412+
'<option>B</option>' +
413+
'</optgroup>' +
414+
'</select>');
415+
416+
expect(element).toEqualSelect('A', 'B');
417+
expect(scope.selection).toBeUndefined();
418+
419+
scope.$apply(function() {
420+
scope.selection = ['A'];
421+
});
422+
expect(element).toEqualSelect(['A'], 'B');
423+
424+
scope.$apply(function() {
425+
scope.selection.push('B');
426+
});
427+
expect(element).toEqualSelect(['A'], ['B']);
428+
});
408429

409430
it('should require', function() {
410431
compile(

0 commit comments

Comments
 (0)