Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

md-datepicker throw exception #5417

Closed
adoris opened this issue Jun 29, 2017 · 15 comments · Fixed by #5711
Closed

md-datepicker throw exception #5417

adoris opened this issue Jun 29, 2017 · 15 comments · Fixed by #5711
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@adoris
Copy link

adoris commented Jun 29, 2017

What is the issue? *

md-datepicker directive, angilar/core 4.2.4, angular/material 1.1.4
when open the month view,it throw error.
same error from angular 1.5: https://github.com/angular/material/issues/10627

Details:

when you open the day view,you can select a month,and then you will open the month view,you will see nothing. And you open the developer tool,you will see the exception message.
HTML
<md-input-container>
              <label for="ValidFrom">Gültig bis:</label>
              <input mdInput name="ValidTo" [mdDatepicker]="validToDatePicker" [min]="minDate" [max]="maxDate" [(ngModel)]="oe.ValidTo">
              <button mdSuffix [mdDatepickerToggle]="validToDatePicker"></button>
</md-input-container>
            <md-datepicker #validToDatePicker  md-placeholder="Gültig bis" class="field-input full-width"></md-datepicker>

ERROR

 Error: Uncaught (in promise): TypeError: date.getFullYear is not a function
TypeError: date.getFullYear is not a function
    at NativeDateAdapter.webpackJsonp.../../../material/@angular/material.es5.js.NativeDateAdapter.getYear (http://localhost:4200/vendor.bundle.js:97255:21)
    at NativeDateAdapter.webpackJsonp.../../../material/@angular/material.es5.js.DateAdapter.compareDate (http://localhost:4200/vendor.bundle.js:97168:43)
    at MdDatepickerInput._minValidator (http://localhost:4200/vendor.bundle.js:112974:36)
    at http://localhost:4200/vendor.bundle.js:83175:49
    at Array.map (native)
    at _executeValidators (http://localhost:4200/vendor.bundle.js:83175:23)
    at MdDatepickerInput._validator (http://localhost:4200/vendor.bundle.js:83131:33)
    at MdDatepickerInput.webpackJsonp.../../../material/@angular/material.es5.js.MdDatepickerInput.validate (http://localhost:4200/vendor.bundle.js:113140:39)
    at http://localhost:4200/vendor.bundle.js:83423:52
    at http://localhost:4200/vendor.bundle.js:83175:49
    at NativeDateAdapter.webpackJsonp.../../../material/@angular/material.es5.js.NativeDateAdapter.getYear (http://localhost:4200/vendor.bundle.js:97255:21)
    at NativeDateAdapter.webpackJsonp.../../../material/@angular/material.es5.js.DateAdapter.compareDate (http://localhost:4200/vendor.bundle.js:97168:43)
    at MdDatepickerInput._minValidator (http://localhost:4200/vendor.bundle.js:112974:36)
    at http://localhost:4200/vendor.bundle.js:83175:49
    at Array.map (native)
    at _executeValidators (http://localhost:4200/vendor.bundle.js:83175:23)
    at MdDatepickerInput._validator (http://localhost:4200/vendor.bundle.js:83131:33)
    at MdDatepickerInput.webpackJsonp.../../../material/@angular/material.es5.js.MdDatepickerInput.validate (http://localhost:4200/vendor.bundle.js:113140:39)
    at http://localhost:4200/vendor.bundle.js:83423:52
    at http://localhost:4200/vendor.bundle.js:83175:49
    at resolvePromise (http://localhost:4200/polyfills.bundle.js:6315:31)
    at http://localhost:4200/polyfills.bundle.js:6366:17
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.bundle.js:5969:31)
    at Object.onInvokeTask (http://localhost:4200/vendor.bundle.js:71783:37)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.bundle.js:5968:36)
    at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.bundle.js:5736:47)
    at drainMicroTaskQueue (http://localhost:4200/polyfills.bundle.js:6129:35)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:4200/polyfills.bundle.js:6035:25)

tested on:

Win10, Chrome 59.0.3071.115
Win10, IE11
Win10, Firefox 54.0
@donroyco
Copy link
Contributor

@adoris If you are using angular/material 1.1.4 with angular/core 4.2.4, you are not using the correct setup. Please use angular/material 2.0.0-beta.7 with angular/core 4.2.4.

@kbchandiran
Copy link

@donroyco i am using angular/material 2.0.0-beta.7 with angular/core 4.2.4. but now also same issue

@jelbourn jelbourn added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Jul 7, 2017
@jelbourn
Copy link
Member

jelbourn commented Jul 7, 2017

@mmalerba sounds like there a situation that leads to trying to call getFullYear on a null/undefined value in the native date adapter

@jelbourn jelbourn closed this as completed Jul 7, 2017
@mmalerba
Copy link
Contributor

mmalerba commented Jul 7, 2017

@jelbourn I assume you didn't mean to close this?

@mmalerba mmalerba reopened this Jul 7, 2017
@jelbourn
Copy link
Member

jelbourn commented Jul 7, 2017

Yeah, clicked the wrong button

@justingish
Copy link

I'm seeing the same thing, but only if I try to set a Min or Max on the input.

@mmalerba
Copy link
Contributor

mmalerba commented Jul 7, 2017

@adoris @justingish can one of you please provide a plunker reproduction, this plunker seems to show it working correctly: http://plnkr.co/edit/iz3QNo4mBtjGYbWfo8ZU?p=preview

@mmalerba mmalerba added the cannot reproduce The team is unable to reproduce this issue with the information provided label Jul 7, 2017
@mmalerba
Copy link
Contributor

Closing this as I cannot reproduce, if you are still seeing the issue feel free to provide a reproduction link and I will re-open.

@justingish
Copy link

It was user error. I was binding the input to a string, not an actual date object. I am using reactive forms, if that makes a difference.

However, I do believe there is room for improvement here because the Min and Max directives are behaving differently than the mdDatePicker. Binding to a string (eg... '2017-7-5) works just fine for the date picker control until you add a min or max directive to the control.

I have created a plunker to show the issue: http://plnkr.co/edit/Iih5lyGbLO1p5pgriWZK?p=preview

@mmalerba
Copy link
Contributor

@justingish Thanks for the plunker, that does seem a little strange/inconsistent, reopening.

@mmalerba mmalerba reopened this Jul 12, 2017
@mmalerba mmalerba removed the cannot reproduce The team is unable to reproduce this issue with the information provided label Jul 12, 2017
@andlcool
Copy link

andlcool commented Jul 15, 2017

I am also facing this error. My situation is when i bind it to a formControl in reactive forms.

Error:

<input mdInput [mdDatepicker]="deadlineDatePicker" [min]="minDate" placeholder="Choose a date" formControlName="deadline">
<button mdSuffix [mdDatepickerToggle]="deadlineDatePicker">

<md-datepicker #deadlineDatePicker>

No error:

<input mdInput [mdDatepicker]="deadlineDatePicker" [min]="minDate" placeholder="Choose a date">
<button mdSuffix [mdDatepickerToggle]="deadlineDatePicker">

<md-datepicker #deadlineDatePicker>

@adoris
Copy link
Author

adoris commented Jul 15, 2017

Error is still here using angular/material 2.0.0-beta.8 with angular/core 4.3.0.
'minDate', 'maxDate' and 'oe.ValidTo' are of type "Date".

@mmalerba
Copy link
Contributor

I have a PR open to make the behavior more consistent by also throwing errors when developers attempt to set the value to type other than the type expected by the DateAdapter. In the case of the NatvieDateAdapter this means strings will no longer be considered valid (this is error prone since the way that string is parsed may vary depending on locale). After #5711 lands you will need to make sure you're working with actual Date objects if you want to use the NativeDateAdapter.

@justingish
Copy link

That seems like a good fix. Plus the error message is clear so it will be simple to solve for anyone who mistakenly sends in a string rather than a date.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants