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

Commit 89ff228

Browse files
committed
fix(datepicker): set datepicker touched if bluring input or closing the pane
Fixes #6598
1 parent 0e334cd commit 89ff228

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/components/datepicker/datePicker.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@
574574
this.calendarPaneOpenedFrom = null;
575575
this.$mdUtil.enableScrolling();
576576

577+
this.ngModelCtrl.$setTouched();
578+
577579
this.documentElement.off('click touchstart', this.bodyClickHandler);
578580
window.removeEventListener('resize', this.windowResizeHandler);
579581
}
@@ -598,6 +600,9 @@
598600
* @param {boolean} isFocused
599601
*/
600602
DatePickerCtrl.prototype.setFocused = function(isFocused) {
603+
if (!isFocused) {
604+
this.ngModelCtrl.$setTouched();
605+
}
601606
this.isFocused = isFocused;
602607
};
603608

src/components/datepicker/datePicker.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,28 @@ describe('md-date-picker', function() {
293293
expect(controller.ngModelCtrl.$modelValue).toEqual(initialDate);
294294
});
295295

296+
it('shoud become touched from bluring closing the pane', function() {
297+
populateInputElement('17/1/2015');
298+
299+
controller.openCalendarPane({
300+
target: controller.inputElement
301+
});
302+
controller.closeCalendarPane();
303+
304+
expect(controller.ngModelCtrl.$touched).toBe(true);
305+
});
306+
307+
it('should become touch from bluring the input', function() {
308+
populateInputElement('17/1/2015');
309+
310+
var input = angular.element(controller.inputElement);
311+
312+
input.triggerHandler('focus');
313+
input.triggerHandler('blur');
314+
315+
expect(controller.ngModelCtrl.$touched).toBe(true);
316+
});
317+
296318
it('should not update the input string is not "complete"', function() {
297319
var date = new Date(2015, DEC, 1);
298320
pageScope.myDate = date;

0 commit comments

Comments
 (0)