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

Commit

Permalink
fix(select): auto-select new option that is marked as selected
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lgalfaso committed Apr 20, 2014
1 parent 1192531 commit 9c66807
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
};


self.addOption = function(value) {
self.addOption = function(value, element) {
assertNotHasOwnProperty(value, '"option value"');
optionsMap[value] = true;

if (ngModelCtrl.$viewValue == value) {
$element.val(value);
if (unknownOption.parent()) unknownOption.remove();
}
if (element.attr('selected') === 'selected') {
element[0].selected = true;
}
};


Expand Down Expand Up @@ -622,10 +625,10 @@ var optionDirective = ['$interpolate', function($interpolate) {
scope.$watch(interpolateFn, function interpolateWatchAction(newVal, oldVal) {
attr.$set('value', newVal);
if (newVal !== oldVal) selectCtrl.removeOption(oldVal);
selectCtrl.addOption(newVal);
selectCtrl.addOption(newVal, element);
});
} else {
selectCtrl.addOption(attr.value);
selectCtrl.addOption(attr.value, element);
}

element.on('$destroy', function() {
Expand Down

0 comments on commit 9c66807

Please sign in to comment.