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

Commit

Permalink
fix(ng:options): select correct element when '?'-option was previousl…
Browse files Browse the repository at this point in the history
…y selected

Closes #599
  • Loading branch information
TEHEK authored and IgorMinar committed Oct 18, 2011
1 parent 74379df commit ee6af9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/widget/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ angularWidget('select', function(element){
if (existingOption.id !== option.id) {
lastElement.val(existingOption.id = option.id);
}
if (existingOption.selected !== option.selected) {
if (existingOption.element.selected !== option.selected) {
lastElement.prop('selected', (existingOption.selected = option.selected));
}
} else {
Expand Down
17 changes: 15 additions & 2 deletions test/widget/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ describe('select', function() {
expect(select.val()).toEqual('0');
expect(select.find('option').length).toEqual(1);
});

it('should select correct input if previously selected option was "?"', function() {
createSingleSelect();
scope.values = [{name:'A'},{name:'B'}];
scope.selected = {};
scope.$digest();
expect(select.find('option').length).toEqual(3);
expect(select.val()).toEqual('?');
expect(select.find('option').eq(0).val()).toEqual('?');

browserTrigger(select.find('option').eq(1));
expect(select.val()).toEqual('0');
expect(select.find('option').eq(0).prop('selected')).toBeTruthy();
expect(select.find('option').length).toEqual(2);
});
});

describe('on change', function() {
Expand Down Expand Up @@ -504,7 +519,5 @@ describe('select', function() {
expect(scope.selected).toEqual([scope.values[0]]);
});
});

});

});

0 comments on commit ee6af9a

Please sign in to comment.