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

Commit ee6af9a

Browse files
TEHEKIgorMinar
authored andcommitted
fix(ng:options): select correct element when '?'-option was previously selected
Closes #599
1 parent 74379df commit ee6af9a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/widget/select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ angularWidget('select', function(element){
384384
if (existingOption.id !== option.id) {
385385
lastElement.val(existingOption.id = option.id);
386386
}
387-
if (existingOption.selected !== option.selected) {
387+
if (existingOption.element.selected !== option.selected) {
388388
lastElement.prop('selected', (existingOption.selected = option.selected));
389389
}
390390
} else {

test/widget/selectSpec.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,21 @@ describe('select', function() {
428428
expect(select.val()).toEqual('0');
429429
expect(select.find('option').length).toEqual(1);
430430
});
431+
432+
it('should select correct input if previously selected option was "?"', function() {
433+
createSingleSelect();
434+
scope.values = [{name:'A'},{name:'B'}];
435+
scope.selected = {};
436+
scope.$digest();
437+
expect(select.find('option').length).toEqual(3);
438+
expect(select.val()).toEqual('?');
439+
expect(select.find('option').eq(0).val()).toEqual('?');
440+
441+
browserTrigger(select.find('option').eq(1));
442+
expect(select.val()).toEqual('0');
443+
expect(select.find('option').eq(0).prop('selected')).toBeTruthy();
444+
expect(select.find('option').length).toEqual(2);
445+
});
431446
});
432447

433448
describe('on change', function() {
@@ -504,7 +519,5 @@ describe('select', function() {
504519
expect(scope.selected).toEqual([scope.values[0]]);
505520
});
506521
});
507-
508522
});
509-
510523
});

0 commit comments

Comments
 (0)