Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 14e3ba8

Browse files
committedJul 8, 2014
Merge pull request #7136 from lgalfaso/issue-6828
fix(jqLite): Chrome specific issue for `<select required>`
2 parents 36831ec + c3a0bcc commit 14e3ba8

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)
This repository has been archived.