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

Commit c7a2028

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

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
@@ -733,7 +733,8 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
733733
// Check to see if the value has changed due to the update to the options
734734
if (!ngModelCtrl.$isEmpty(previousValue)) {
735735
var nextValue = selectCtrl.readValue();
736-
if (ngOptions.trackBy ? !equals(previousValue, nextValue) : previousValue !== nextValue) {
736+
var isNotPrimitive = ngOptions.trackBy || multiple;
737+
if (isNotPrimitive ? !equals(previousValue, nextValue) : previousValue !== nextValue) {
737738
ngModelCtrl.$setViewValue(nextValue);
738739
ngModelCtrl.$render();
739740
}

test/ng/directive/ngOptionsSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -2654,5 +2654,20 @@ describe('ngOptions', function() {
26542654
expect(scope.value).toBe('third');
26552655
expect(element).toEqualSelectValue('third');
26562656
}));
2657+
2658+
it('should not set $dirty with select-multiple after compilation', function() {
2659+
scope.values = ['a', 'b'];
2660+
scope.selected = ['b'];
2661+
2662+
createSelect({
2663+
'ng-model':'selected',
2664+
'multiple':true,
2665+
'ng-options':'value for value in values',
2666+
'name': 'select'
2667+
});
2668+
2669+
expect(element.find('option')[1].selected).toBe(true);
2670+
expect(scope.form.select.$pristine).toBe(true);
2671+
});
26572672
});
26582673
});

0 commit comments

Comments
 (0)