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

Commit 66065db

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(datepicker): respond to external error state changes
Fixes the datepicker not responding, if something external changes the error state. For example, if the element has `ng-required` that depends on another input's value. Fixes #8878. Closes #9048
1 parent 2a05176 commit 66065db

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/components/datepicker/js/datepickerDirective.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@
363363
self.resizeInputElement();
364364
self.updateErrorState();
365365
};
366+
367+
// Responds to external error state changes (e.g. ng-required based on another input).
368+
ngModelCtrl.$viewChangeListeners.unshift(angular.bind(this, this.updateErrorState));
366369
};
367370

368371
/**

src/components/datepicker/js/datepickerDirective.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ describe('md-datepicker', function() {
321321
expect(controller.inputContainer).toHaveClass('md-datepicker-invalid');
322322
});
323323

324+
it('should toggle the invalid class when an external value causes the error state to change', function() {
325+
pageScope.isRequired = true;
326+
populateInputElement('');
327+
expect(controller.inputContainer).toHaveClass('md-datepicker-invalid');
328+
329+
pageScope.$apply(function() {
330+
pageScope.isRequired = false;
331+
});
332+
expect(controller.inputContainer).not.toHaveClass('md-datepicker-invalid');
333+
});
334+
324335
it('should not update the model when value is not enabled', function() {
325336
pageScope.dateFilter = function(date) {
326337
return date.getDay() === 1;

0 commit comments

Comments
 (0)