Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Datepicker 0.13.0 - throws date error on textbox change with Angular 1.3.5 stable #3609

Closed
johnsonlin opened this issue May 4, 2015 · 7 comments

Comments

@johnsonlin
Copy link

I tried to implement the new angular ui bootstrap with angular 1.3.5 stable.
Here's a plunker demo:
http://plnkr.co/edit/6jWsI4nk6hyjh2l6O5Pd?p=preview

when I change the year of second date, which is generated by new Date(), everything updates accordingly.

But when i change the year of first date, which is generated by new Date(1430229600000), it throws an error unless I manually select another date from the datepicker.

Datepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or ISO 8601 date.

After selecting another date from the datepicker, it behaves like the second date with no errors.

@johnsonlin johnsonlin changed the title Datepicker 0.13.0 - throws date error on textbox change Datepicker 0.13.0 - throws date error on textbox change with Angular 1.3.5 stable May 4, 2015
@chrisirhc
Copy link
Contributor

What is the error message you're seeing?
I don't see an error message when I change the year by replacing 2015 with 2016 on the first date .

Also, I saw that you're using minDate with a null minDate, that evaluates to a minimum date of null. You might want to remove the min-date="minDate" and see if that's causing the problem.

@johnsonlin
Copy link
Author

JS Error in console:
Datepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or ISO 8601 date.

@chrisirhc
Copy link
Contributor

Ah, I see. This is related to #3294 .
Actually, new Date('28/04/201') fails because 28 cannot be the value of the months field (in US date locale). new Date('03/05/201') parses but actually fails, because it's interpreting 03 as the months.

This is a known issue, I believe we intend to break this behavior soon. When we merge in #3294, the ng-model should get null when the format is invalid. In this case, the format is invalid because the yyyy is not satisfied, there should be 4 digits in the year and the ng-model fail on parsing it.

@chrisirhc chrisirhc added this to the 0.13.x milestone May 4, 2015
@johnsonlin
Copy link
Author

@chrisirhc
Hi Chris,
the date format is correct as I'm using Australian date locale (dd/MM/yyyy) in the demo.
so new Date('28/04/201') is actually 28-April-201
try deleting the last 2 digits of 2015 and putting 01 after it
then you'll see the js error on the first date but not the second date as the second date converts the year.

and after trying a few different date formats from the dropdown, it looks like datepicker will fail to parse any formats that end with yyyy

Please look into it.

Thanks

@chrisirhc
Copy link
Contributor

Yes, it works only because you're in Australia. This behavior shouldn't be relied upon because it will not work, in say USA, where the locale's default date format is different from the specified date format.

I think the failure to parse is actually the correct behavior as it's more expected and reliable. However, it shouldn't throw that error in the console. It should just set the ng-model to null and mark the ng-model with invalid input (only while the year is 201). We'll fix that soon once that PR is merged.

@johnsonlin johnsonlin reopened this May 4, 2015
@johnsonlin
Copy link
Author

Hi Chris,
Just want to make sure that I understand the fix.
When I try to change the date value 28/04/2015 to 28/04/2005, I highlight the last 2 letters 15 then start typing the first letter 0.
Then datepicker will failed to parse the value and fail.
What do I see in the text box?

  • Do I see 28/04/200 in the text box? (After I type the other letter 5, will it pass the date parse and work again?)

OR

  • Do I see the text box value get empty as ng-model is set to null?

@chrisirhc
Copy link
Contributor

You should see 28/04/200 in text box and typing 5, it'll pass the date parsing. That's the intended behavior, but it might be broken at the moment. See #3736

@wesleycho wesleycho modified the milestones: 0.13.1 (Performance), 0.13.x Jun 5, 2015
@wesleycho wesleycho modified the milestones: 0.13.1 (npm), 0.13.2 (Performance) Jul 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants