-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Binding in select with multiple using optgroups fails #1553
Comments
Can you be clear what you expect it to do? In this fiddle, it looks like you are expecting multiple selections but the select is not multiple. |
@petebacondarwin I just hit this issue and created a fiddle demonstrating it: http://jsfiddle.net/YESMG/1/ is it clear now that this is a bug? if so, any pointers on how to fix? not sure if @cgross is still interested in a fix, but I sure am. will update this issue with any progress. |
I dug into the The following patch (against angular.js 1.0.2) fixes the issue in the fiddle linked above: diff --git a/app/lib/angular/angular.js b/app/lib/angular/angular.js
index ed50432..6d4465e 100644
--- a/app/lib/angular/angular.js
+++ b/app/lib/angular/angular.js
@@ -14101,10 +14101,16 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selectElement.bind('change', function() {
scope.$apply(function() {
var array = [];
- forEach(selectElement.children(), function(option) {
+ function addIfSelected(option) {
if (option.selected) {
array.push(option.value);
}
+ }
+ forEach(selectElement.children(), function(child) {
+ if (child.tagName == 'OPTION')
+ addIfSelected(child);
+ else if (child.tagName == 'OPTGROUP')
+ forEach(child.getElementsByTagName('option'), addIfSelected);
});
ctrl.$setViewValue(array);
}); Could someone pick up the ball and run with it from here to get a full fix applied? |
submitted pull request #1629 |
If I create a and use for groupings. The selected items aren't applied to the ng-model binding. Another person already created a fiddle demonstrating the issue: http://jsfiddle.net/laguiz/MDeme/1/
The text was updated successfully, but these errors were encountered: