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

Commit 8bc2667

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 1192531 commit 8bc2667

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
@@ -163,14 +163,20 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
163163
};
164164

165165

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

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

176182

@@ -622,10 +628,10 @@ var optionDirective = ['$interpolate', function($interpolate) {
622628
scope.$watch(interpolateFn, function interpolateWatchAction(newVal, oldVal) {
623629
attr.$set('value', newVal);
624630
if (newVal !== oldVal) selectCtrl.removeOption(oldVal);
625-
selectCtrl.addOption(newVal);
631+
selectCtrl.addOption(newVal, element);
626632
});
627633
} else {
628-
selectCtrl.addOption(attr.value);
634+
selectCtrl.addOption(attr.value, element);
629635
}
630636

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

0 commit comments

Comments
 (0)