Skip to content

Commit 6ae6b47

Browse files
author
Erin Altenhof-Long
committed
revert(select): avoid checking option element selected properties in render
This reverts commit dc149de. This commit fixes a bug caused by Firefox updating select.value on hover. However, it causes other bugs with select including the issue described in angular#7715. This issue causes selects with a blank disabled option to skip to the second option. A bug has been filed to deal with the Firefox issue addressed by this commit, and alternate Angular fixes are being investigated. The test introduced in this commit does test a valid case and should be added back if an Angular solution to the issue is being pursued.
1 parent 7f5e0f0 commit 6ae6b47

File tree

2 files changed

+1
-28
lines changed

2 files changed

+1
-28
lines changed

src/ng/directive/select.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
394394
value = valueFn(scope, locals);
395395
}
396396
}
397-
// Update the null option's selected property here so $render cleans it up correctly
398-
if (optionGroupsCache[0].length > 1) {
399-
if (optionGroupsCache[0][1].id !== key) {
400-
optionGroupsCache[0][1].selected = false;
401-
}
402-
}
403397
}
404398
ctrl.$setViewValue(value);
405399
});
@@ -537,7 +531,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
537531
lastElement.val(existingOption.id = option.id);
538532
}
539533
// lastElement.prop('selected') provided by jQuery has side-effects
540-
if (existingOption.selected !== option.selected) {
534+
if (lastElement[0].selected !== option.selected) {
541535
lastElement.prop('selected', (existingOption.selected = option.selected));
542536
}
543537
} else {

test/ng/directive/selectSpec.js

-21
Original file line numberDiff line numberDiff line change
@@ -733,27 +733,6 @@ describe('select', function() {
733733
expect(sortedHtml(options[2])).toEqual('<option value="1">3</option>');
734734
});
735735

736-
it('should not update selected property of an option element on digest with no change event',
737-
function() {
738-
createSingleSelect();
739-
740-
scope.$apply(function() {
741-
scope.values = [{name: 'A'}, {name: 'B'}, {name: 'C'}];
742-
scope.selected = scope.values[0];
743-
});
744-
745-
var options = element.find('option');
746-
var optionToSelect = options.eq(1);
747-
748-
expect(optionToSelect.text()).toBe('B');
749-
750-
optionToSelect.prop('selected', true);
751-
scope.$digest();
752-
753-
expect(optionToSelect.prop('selected')).toBe(true);
754-
expect(scope.selected).toBe(scope.values[0]);
755-
});
756-
757736
describe('binding', function() {
758737

759738
it('should bind to scope value', function() {

0 commit comments

Comments
 (0)