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

Commit 83f4d5e

Browse files
committed
fix(datepicker): fix input always being required.
1 parent 3d6077b commit 83f4d5e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/components/datepicker/datePicker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,15 @@
367367
* @param {Date=} opt_date Date to check. If not given, defaults to the datepicker's model value.
368368
*/
369369
DatePickerCtrl.prototype.updateErrorState = function(opt_date) {
370-
// Force all dates to midnight in order to ignore the time portion.
371-
var date = this.dateUtil.createDateAtMidnight(opt_date || this.date);
370+
var date = opt_date || this.date;
372371

373372
// Clear any existing errors to get rid of anything that's no longer relevant.
374373
this.clearErrorState();
375374

376375
if (this.dateUtil.isValidDate(date)) {
376+
// Force all dates to midnight in order to ignore the time portion.
377+
date = this.dateUtil.createDateAtMidnight(date);
378+
377379
if (this.dateUtil.isValidDate(this.minDate)) {
378380
var minDate = this.dateUtil.createDateAtMidnight(this.minDate);
379381
this.ngModelCtrl.$setValidity('mindate', date >= minDate);

src/components/datepicker/datePicker.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ describe('md-date-picker', function() {
189189
expect(controller.ngModelCtrl.$error['mindate']).toBeFalsy();
190190
});
191191

192+
it('should not enforce `required` when a min-date is set', function() {
193+
pageScope.isRequired = false;
194+
pageScope.minDate = new Date(2015, JAN, 1);
195+
pageScope.myDate = null;
196+
pageScope.$apply();
197+
198+
expect(controller.ngModelCtrl.$error['mindate']).toBeFalsy();
199+
});
200+
201+
it('should not enforce `required` when a max-date is set', function() {
202+
pageScope.isRequired = false;
203+
pageScope.maxDate = new Date(2015, JAN, 1);
204+
pageScope.myDate = null;
205+
pageScope.$apply();
206+
207+
expect(controller.ngModelCtrl.$error['mindate']).toBeFalsy();
208+
});
209+
192210
describe('inside of a form element', function() {
193211
var formCtrl;
194212

0 commit comments

Comments
 (0)