From fec16a4972fe9e0b55e7ba7f23f2c9052001fb17 Mon Sep 17 00:00:00 2001 From: TEHEK Firefox Date: Wed, 12 Oct 2011 23:42:21 +0000 Subject: [PATCH 1/2] fix(ng:options): select correct element when '?'-option was previously selected Closes #599 --- src/widget/select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/select.js b/src/widget/select.js index 8184d8f9ff95..2448d40cdf66 100644 --- a/src/widget/select.js +++ b/src/widget/select.js @@ -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 { From 38ea53ec432fcaaaf18d50794a0dae9ab72897e3 Mon Sep 17 00:00:00 2001 From: TEHEK Firefox Date: Thu, 13 Oct 2011 15:22:50 +0000 Subject: [PATCH 2/2] fix(ng:options): select correct element when '?'-option was previously selected Closes #599 --- test/widget/selectSpec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/widget/selectSpec.js b/test/widget/selectSpec.js index dd1dc0cb7eef..f75899cfa958 100644 --- a/test/widget/selectSpec.js +++ b/test/widget/selectSpec.js @@ -428,6 +428,22 @@ describe('select', function() { expect(select.val()).toEqual('0'); expect(select.find('option').length).toEqual(1); }); + + it('should select correct input if previously bound to something not in the list', function() { + createSingleSelect(); + scope.values = [{name:'A'},{name:'B'}]; + scope.selected = {}; + scope.$digest(); + expect(select.find('option').length).toEqual(3); + expect(select.val()).toEqual('?'); + expect(jqLite(select.find('option')[0]).val()).toEqual('?'); + + select.find('option').eq(1).prop('selected', true); + browserTrigger(select, 'change'); + 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() {