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

Commit f163c90

Browse files
m-amrNarretz
authored andcommitted
fix(ngOptions): don't $dirty multiple select after compilation
Closes #13211 Closes #13326
1 parent 4e94864 commit f163c90

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/directive/ngOptions.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
737737
// Check to see if the value has changed due to the update to the options
738738
if (!ngModelCtrl.$isEmpty(previousValue)) {
739739
var nextValue = selectCtrl.readValue();
740-
if (ngOptions.trackBy ? !equals(previousValue, nextValue) : previousValue !== nextValue) {
740+
var isNotPrimitive = ngOptions.trackBy || multiple;
741+
if (isNotPrimitive ? !equals(previousValue, nextValue) : previousValue !== nextValue) {
741742
ngModelCtrl.$setViewValue(nextValue);
742743
ngModelCtrl.$render();
743744
}

test/ng/directive/ngOptionsSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -2645,5 +2645,20 @@ describe('ngOptions', function() {
26452645
expect(scope.value).toBe('third');
26462646
expect(element).toEqualSelectValue('third');
26472647
}));
2648+
2649+
it('should not set $dirty with select-multiple after compilation', function() {
2650+
scope.values = ['a', 'b'];
2651+
scope.selected = ['b'];
2652+
2653+
createSelect({
2654+
'ng-model':'selected',
2655+
'multiple':true,
2656+
'ng-options':'value for value in values',
2657+
'name': 'select'
2658+
});
2659+
2660+
expect(element.find('option')[1].selected).toBe(true);
2661+
expect(scope.form.select.$pristine).toBe(true);
2662+
});
26482663
});
26492664
});

0 commit comments

Comments
 (0)