material icon indicating copy to clipboard operation
material copied to clipboard

md-datepicker with min/max date gets error

Open djmarcus1 opened this issue 11 years ago • 6 comments

When I use the md-datepicker with no min/max dates, it works fine.

When I add the min/max dates:

<md-datepicker ng-model="settings.effectiveDate" md-min-date="09/21/2015" md-max-date="09/10/2017"></md-datepicker>

...I get the following error:

TypeError: end.getFullYear is not a function

The error reminded me of the javascript Date object. So I changed the code to:

    $scope.minDate = new Date(2015, 8, 21);
    $scope.maxDate = new Date(2017, 8, 10);

and

    <md-datepicker ng-model="settings.effectiveDate" md-min-date="minDate" md-max-date="maxDate"></md-datepicker>

It Works!

So, it appears that the min/max values MUST be Date objects.

The documentation (https://material.angularjs.org/HEAD/#/api/material.components.datepicker/directive/mdDatepicker) does not say anything about the expression type.

The short term solution is to update the documentation to say the expression must evaluate to a Date object.

The longer term solution is to support either Date objects or string objects (ex: moment.format('MM/DD/YYYY').

djmarcus1 avatar Sep 20 '15 20:09 djmarcus1

The documentation here demonstrates how to use minDate and maxDate.

To view it either open the CodePen or click on <> to View Source and then the JS tab.

Ideally, this kind of question would be first asked on the forums.

Splaktar avatar Sep 21 '15 01:09 Splaktar

For sure you are correct.. I will post additional q's on the forums. Thanks for the link.

djmarcus1 avatar Sep 22 '15 03:09 djmarcus1

For now it's going to continue just being a Date object, which string input possibly coming later as a feature (maybe as a community PR). Need to update the docs.

jelbourn avatar Sep 22 '15 17:09 jelbourn

Not working as expected when on years view. Showing years only starting from 2014 instead of 1995.

ref here: http://codepen.io/pen/rLypoy

snavaneeth78 avatar Jun 28 '16 18:06 snavaneeth78

Still can't set a maxdate on the years view. Does somebody knows a solution?

sjoerdvalk1991 avatar Dec 07 '17 11:12 sjoerdvalk1991

@sjoerdvalk1991 Please try Stack Overflow, Gitter, or the AngularJS Material forums.

Splaktar avatar May 09 '19 22:05 Splaktar