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

Commit b8ae73e

Browse files
committed
fix(select): auto-select new option that is marked as selected
When adding a new <option> element, if the DOM of this option element states that the element is marked as `selected`, then select the new <option> element Closes #6828
1 parent 36831ec commit b8ae73e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ng/directive/select.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,20 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
164164
};
165165

166166

167-
self.addOption = function(value) {
167+
self.addOption = function(value, element) {
168168
assertNotHasOwnProperty(value, '"option value"');
169169
optionsMap[value] = true;
170170

171171
if (ngModelCtrl.$viewValue == value) {
172172
$element.val(value);
173173
if (unknownOption.parent()) unknownOption.remove();
174174
}
175+
// Workaround for https://code.google.com/p/chromium/issues/detail?id=381459
176+
// Adding an <option selected="selected"> element to a <select required="required"> should
177+
// automatically select the new element
178+
if (element[0].hasAttribute('selected')) {
179+
element[0].selected = true;
180+
}
175181
};
176182

177183

@@ -625,10 +631,10 @@ var optionDirective = ['$interpolate', function($interpolate) {
625631
if (oldVal !== newVal) {
626632
selectCtrl.removeOption(oldVal);
627633
}
628-
selectCtrl.addOption(newVal);
634+
selectCtrl.addOption(newVal, element);
629635
});
630636
} else {
631-
selectCtrl.addOption(attr.value);
637+
selectCtrl.addOption(attr.value, element);
632638
}
633639

634640
element.on('$destroy', function() {

0 commit comments

Comments
 (0)