Skip to content

Commit 30b4813

Browse files
fix(select): remove unknown option when model is undefined and empty option is available
Closes angular#11078 Closes angular#11092
1 parent da9eac8 commit 30b4813

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/ng/directive/select.js

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ var SelectController =
7373
if (value === '') self.emptyOption.prop('selected', true); // to make IE9 happy
7474
} else {
7575
if (isUndefined(value) && self.emptyOption) {
76+
self.removeUnknownOption();
7677
$element.val('');
7778
} else {
7879
self.renderUnknownOption(value);

test/ng/directive/selectSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,23 @@ describe('select', function() {
237237
});
238238

239239

240+
it('should remove unknown option when model is undefined', function() {
241+
scope.robot = 'other';
242+
compile('<select ng-model="robot">' +
243+
'<option value="">--select--</option>' +
244+
'<option value="x">robot x</option>' +
245+
'<option value="y">robot y</option>' +
246+
'</select>');
247+
248+
expect(element).toEqualSelect([unknownValue('other')], '', 'x', 'y');
249+
250+
scope.robot = undefined;
251+
scope.$digest();
252+
253+
expect(element).toEqualSelect([''], 'x', 'y');
254+
});
255+
256+
240257
describe('interactions with repeated options', function() {
241258

242259
it('should select empty option when model is undefined', function() {

0 commit comments

Comments
 (0)