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

Commit 7256670

Browse files
alopezsanchezandrewseguin
authored andcommitted
fix(select multiple): set the element dirty when the selected options change (#10749)
Fixes #10584. `ngModel.$setPristine()` was executed each time the selected options changed.
1 parent 0ffbe8a commit 7256670

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/components/select/select.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
704704
// reference. This allowed the developer to also push and pop from their array.
705705
$scope.$watchCollection(self.modelBinding, function(value) {
706706
if (validateArray(value)) renderMultiple(value);
707-
self.ngModel.$setPristine();
708707
});
709708

710709
ngModel.$isEmpty = function(value) {

src/components/select/select.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,27 @@ describe('<md-select>', function() {
12031203
expect(selectMenu.hasAttribute('multiple')).toBe(false);
12041204
});
12051205

1206+
it('should set the element dirty when selected options changes', function () {
1207+
$rootScope.model = 2;
1208+
$rootScope.opts = [1, 2, 3, 4];
1209+
var form = $compile('<form name="testForm">' +
1210+
'<md-select multiple="multiple" ng-model="model" name="multiSelect">' +
1211+
'<md-option ng-repeat="opt in opts" ng-value="opt">{{opt}}</md-option>' +
1212+
'</md-select></form>')($rootScope);
1213+
var el = form.find('md-select');
1214+
1215+
$rootScope.$digest();
1216+
$timeout.flush();
1217+
1218+
expect($rootScope.testForm.multiSelect.$pristine).toBe(true);
1219+
expect($rootScope.testForm.multiSelect.$dirty).toBe(false);
1220+
1221+
openSelect(el);
1222+
clickOption(el, 0);
1223+
1224+
expect($rootScope.testForm.multiSelect.$pristine).toBe(false);
1225+
expect($rootScope.testForm.multiSelect.$dirty).toBe(true);
1226+
});
12061227
});
12071228
});
12081229

0 commit comments

Comments
 (0)