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

fix for issue #1553 #1629

Closed
wants to merge 2 commits 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
4 changes: 2 additions & 2 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
};
Expand All @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,27 @@ describe('select', function() {
expect(element).toEqualSelect(['A'], ['B']);
});

it('should work with optgroups', function() {
compile('<select ng-model="selection" multiple>' +
'<optgroup label="group1">' +
'<option>A</option>' +
'<option>B</option>' +
'</optgroup>' +
'</select>');

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