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

Commit

Permalink
fix(select): prevent unknown option being added to select when bound …
Browse files Browse the repository at this point in the history
…to null property

If a select directive was bound, using ng-model, to a property with a value of null this would
result in an unknown option being added to the select element with the value "? object:null ?".
This change prevents a null value from adding an unknown option meaning that the extra option is
not added as a child of the select element.

Since select (without ngOptions) can only have string value options then `null` was never a
viable option value, so this is not a breaking change.

Closes #11872
Closes #11875
  • Loading branch information
petebacondarwin committed May 18, 2015
1 parent 0515614 commit 9e3f82b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ng/directive/select.js
Expand Up @@ -316,7 +316,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selectElement.val(viewValue);
if (viewValue === '') emptyOption.prop('selected', true); // to make IE9 happy
} else {
if (isUndefined(viewValue) && emptyOption) {
if (viewValue == null && emptyOption) {
selectElement.val('');
} else {
selectCtrl.renderUnknownOption(viewValue);
Expand Down
2 changes: 1 addition & 1 deletion test/ng/directive/selectSpec.js
Expand Up @@ -362,7 +362,7 @@ describe('select', function() {
scope.$apply(function() {
scope.robot = null;
});
expect(element).toEqualSelect(['? object:null ?'], '', 'c3p0', 'r2d2');
expect(element).toEqualSelect([''], 'c3p0', 'r2d2');

scope.$apply(function() {
scope.robot = 'r2d2';
Expand Down

0 comments on commit 9e3f82b

Please sign in to comment.