diff options
| author | TEHEK Firefox | 2011-10-12 23:42:21 +0000 | 
|---|---|---|
| committer | Igor Minar | 2011-10-18 14:02:54 -0700 | 
| commit | ee6af9a97807e1f166da0f7b005f2133a86344d5 (patch) | |
| tree | e98ff9294156a45f0983fe77c663942a34bfa252 | |
| parent | 74379df6c425030d8e3d52d3b1e37b2f45d21d2a (diff) | |
| download | angular.js-ee6af9a97807e1f166da0f7b005f2133a86344d5.tar.bz2 | |
fix(ng:options): select correct element when '?'-option was previously selected
Closes #599
| -rw-r--r-- | src/widget/select.js | 2 | ||||
| -rw-r--r-- | test/widget/selectSpec.js | 17 | 
2 files changed, 16 insertions, 3 deletions
| diff --git a/src/widget/select.js b/src/widget/select.js index 8184d8f9..2448d40c 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 { diff --git a/test/widget/selectSpec.js b/test/widget/selectSpec.js index dd1dc0cb..63699d01 100644 --- a/test/widget/selectSpec.js +++ b/test/widget/selectSpec.js @@ -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() { @@ -504,7 +519,5 @@ describe('select', function() {          expect(scope.selected).toEqual([scope.values[0]]);        });      }); -    }); -  }); | 
