diff options
| author | _pants | 2012-11-29 11:46:51 -0500 | 
|---|---|---|
| committer | Igor Minar | 2012-12-05 02:21:31 +0100 | 
| commit | 54c0d464b0f34f9bfd076883a6a78cf5925bd975 (patch) | |
| tree | 53855b4bb13971f0def038c90d13ba5738ef6484 | |
| parent | cf89e8653cd796308d87d75fa9dd1601227fadec (diff) | |
| download | angular.js-54c0d464b0f34f9bfd076883a6a78cf5925bd975.tar.bz2 | |
fix(select): support optgroup + select[multiple] combo
Closes #1553
| -rw-r--r-- | src/ng/directive/select.js | 4 | ||||
| -rw-r--r-- | test/ng/directive/selectSpec.js | 21 | 
2 files changed, 23 insertions, 2 deletions
| diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 31254592..d82bd139 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);                } diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 7d17a185..2b56228d 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('<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( | 
