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

Commit 87eff27

Browse files
committed
fix(select): remove workaround for Chrome bug
In the Chrome issue (https://bugs.chromium.org/p/chromium/issues/detail?id=381459) I noticed that the bug can't be reproduced in Chrome 45 and the issue was closed subsequently. I've also tested again with Chrome 51 and it still works. Additionally, the Chrome hack was kept in the select code, but wasn't ported to the ngOptions code when the two split in 7fda214, and no regression happened. Nevertheless, a test has been added to guard against a future regression. Related: #6828 PR: #14705
1 parent a478f69 commit 87eff27

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/ng/directive/select.js

-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
var noopNgModelController = { $setViewValue: noop, $render: noop };
44

5-
function chromeHack(optionElement) {
6-
// Workaround for https://code.google.com/p/chromium/issues/detail?id=381459
7-
// Adding an <option selected="selected"> element to a <select required="required"> should
8-
// automatically select the new element
9-
if (optionElement[0].hasAttribute('selected')) {
10-
optionElement[0].selected = true;
11-
}
12-
}
13-
145
/**
156
* @ngdoc type
167
* @name select.SelectController
@@ -90,7 +81,6 @@ var SelectController =
9081
var count = optionsMap.get(value) || 0;
9182
optionsMap.put(value, count + 1);
9283
self.ngModelCtrl.$render();
93-
chromeHack(element);
9484
};
9585

9686
// Tell the select control that an option, with the given value, has been removed

test/ng/directive/ngOptionsSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,23 @@ describe('ngOptions', function() {
26832683
});
26842684
});
26852685

2686+
describe('required and empty option', function() {
2687+
2688+
it('should select the empty option after compilation', function() {
2689+
createSelect({
2690+
'name': 'select',
2691+
'ng-model': 'value',
2692+
'ng-options': 'item for item in [\'first\', \'second\', \'third\']',
2693+
'required': 'required'
2694+
}, true);
2695+
2696+
expect(element.val()).toBe('');
2697+
var emptyOption = element.find('option').eq(0);
2698+
expect(emptyOption.prop('selected')).toBe(true);
2699+
expect(emptyOption.val()).toBe('');
2700+
});
2701+
});
2702+
26862703
describe('ngModelCtrl', function() {
26872704
it('should prefix the model value with the word "the" using $parsers', function() {
26882705
createSelect({

0 commit comments

Comments
 (0)