From 7200ad71483dd1336ce231e4da3c81839b17da18 Mon Sep 17 00:00:00 2001 From: _pants <_pants@anotherwebsite.org> Date: Thu, 29 Nov 2012 11:45:01 -0500 Subject: [PATCH 1/2] add failing test demonstrating bug angular/angular.js#1553 --- test/ng/directive/selectSpec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 7d17a1856fd8..2b56228d17c9 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -405,6 +405,27 @@ describe('select', function() { expect(element).toEqualSelect(['A'], ['B']); }); + it('should work with optgroups', function() { + compile(''); + + expect(element).toEqualSelect('A', 'B'); + expect(scope.selection).toBeUndefined(); + + scope.$apply(function() { + scope.selection = ['A']; + }); + expect(element).toEqualSelect(['A'], 'B'); + + scope.$apply(function() { + scope.selection.push('B'); + }); + expect(element).toEqualSelect(['A'], ['B']); + }); it('should require', function() { compile( From b83574c13e1c4c6aeb21289177d74e25bebafd36 Mon Sep 17 00:00:00 2001 From: _pants <_pants@anotherwebsite.org> Date: Thu, 29 Nov 2012 11:46:51 -0500 Subject: [PATCH 2/2] fix(select): optgroup no longer breaks select multiple angular/angular.js#1553 --- src/ng/directive/select.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 31254592e668..d82bd139c3b2 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -265,7 +265,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { var lastView; ctrl.$render = function() { var items = new HashMap(ctrl.$viewValue); - forEach(selectElement.children(), function(option) { + forEach(selectElement.find('option'), function(option) { option.selected = isDefined(items.get(option.value)); }); }; @@ -282,7 +282,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { selectElement.bind('change', function() { scope.$apply(function() { var array = []; - forEach(selectElement.children(), function(option) { + forEach(selectElement.find('option'), function(option) { if (option.selected) { array.push(option.value); }