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

Commit c348f2c

Browse files
committed
fix(directive): ng:options incorrectly re-grew options on datasource change
Closes #464
1 parent f3456dc commit c348f2c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
### Bug Fixes
55
- Issue #449: [ng:options] should support binding to a property of an item.
6+
- Issue #464: [ng:options] incorrectly re-grew options on datasource change
67

78
### Breaking changes
89
- no longer support MMMMM in filter.date as we need to follow UNICODE LOCALE DATA formats.

src/widgets.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,13 @@ angularWidget('select', function(element){
783783
}
784784
}
785785
}
786-
if (fragment) select.append(jqLite(fragment));
786+
if (fragment) {
787+
select.append(jqLite(fragment));
788+
}
787789
// shrink children
788790
while(optionElements.length > index) {
789791
optionElements.pop().remove();
792+
optionTexts.pop();
790793
delete lastSelectValue[optionElements.length];
791794
}
792795

test/widgetsSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,24 @@ describe("widget", function(){
672672
expect(select.find('option').length).toEqual(1); // we add back the special empty option
673673
});
674674

675+
it('should shrink and then grow list', function(){
676+
createSingleSelect();
677+
scope.values = [{name:'A'}, {name:'B'}, {name:'C'}];
678+
scope.selected = scope.values[0];
679+
scope.$eval();
680+
expect(select.find('option').length).toEqual(3);
681+
682+
scope.values = [{name:'1'}, {name:'2'}];
683+
scope.selected = scope.values[0];
684+
scope.$eval();
685+
expect(select.find('option').length).toEqual(2);
686+
687+
scope.values = [{name:'A'}, {name:'B'}, {name:'C'}];
688+
scope.selected = scope.values[0];
689+
scope.$eval();
690+
expect(select.find('option').length).toEqual(3);
691+
});
692+
675693
it('should update list', function(){
676694
createSingleSelect();
677695
scope.values = [{name:'A'}, {name:'B'}, {name:'C'}];

0 commit comments

Comments
 (0)