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

Commit

Permalink
fix(datepicker): fix input always being required.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Jan 26, 2016
1 parent 3d6077b commit 83f4d5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/datepicker/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,15 @@
* @param {Date=} opt_date Date to check. If not given, defaults to the datepicker's model value.
*/
DatePickerCtrl.prototype.updateErrorState = function(opt_date) {
// Force all dates to midnight in order to ignore the time portion.
var date = this.dateUtil.createDateAtMidnight(opt_date || this.date);
var date = opt_date || this.date;

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

if (this.dateUtil.isValidDate(date)) {
// Force all dates to midnight in order to ignore the time portion.
date = this.dateUtil.createDateAtMidnight(date);

if (this.dateUtil.isValidDate(this.minDate)) {
var minDate = this.dateUtil.createDateAtMidnight(this.minDate);
this.ngModelCtrl.$setValidity('mindate', date >= minDate);
Expand Down
18 changes: 18 additions & 0 deletions src/components/datepicker/datePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ describe('md-date-picker', function() {
expect(controller.ngModelCtrl.$error['mindate']).toBeFalsy();
});

it('should not enforce `required` when a min-date is set', function() {
pageScope.isRequired = false;
pageScope.minDate = new Date(2015, JAN, 1);
pageScope.myDate = null;
pageScope.$apply();

expect(controller.ngModelCtrl.$error['mindate']).toBeFalsy();
});

it('should not enforce `required` when a max-date is set', function() {
pageScope.isRequired = false;
pageScope.maxDate = new Date(2015, JAN, 1);
pageScope.myDate = null;
pageScope.$apply();

expect(controller.ngModelCtrl.$error['mindate']).toBeFalsy();
});

describe('inside of a form element', function() {
var formCtrl;

Expand Down

0 comments on commit 83f4d5e

Please sign in to comment.