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

Commit

Permalink
fix(ngOptions): don't $dirty multiple select after compilation
Browse files Browse the repository at this point in the history
Closes #13211
Closes #13326
  • Loading branch information
m-amr authored and Narretz committed Nov 23, 2015
1 parent 4e94864 commit f163c90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ng/directive/ngOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,8 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
// Check to see if the value has changed due to the update to the options
if (!ngModelCtrl.$isEmpty(previousValue)) {
var nextValue = selectCtrl.readValue();
if (ngOptions.trackBy ? !equals(previousValue, nextValue) : previousValue !== nextValue) {
var isNotPrimitive = ngOptions.trackBy || multiple;
if (isNotPrimitive ? !equals(previousValue, nextValue) : previousValue !== nextValue) {
ngModelCtrl.$setViewValue(nextValue);
ngModelCtrl.$render();
}
Expand Down
15 changes: 15 additions & 0 deletions test/ng/directive/ngOptionsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2645,5 +2645,20 @@ describe('ngOptions', function() {
expect(scope.value).toBe('third');
expect(element).toEqualSelectValue('third');
}));

it('should not set $dirty with select-multiple after compilation', function() {
scope.values = ['a', 'b'];
scope.selected = ['b'];

createSelect({
'ng-model':'selected',
'multiple':true,
'ng-options':'value for value in values',
'name': 'select'
});

expect(element.find('option')[1].selected).toBe(true);
expect(scope.form.select.$pristine).toBe(true);
});
});
});

0 comments on commit f163c90

Please sign in to comment.