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

non-dates are being parsed as valid dates #3104

Closed
bolemeus opened this issue Dec 15, 2014 · 9 comments
Closed

non-dates are being parsed as valid dates #3104

bolemeus opened this issue Dec 15, 2014 · 9 comments

Comments

@bolemeus
Copy link

I have a datepicker on my site, using the following format 'dd-MM-yyyy'.
Because it is possible to manually insert a date I want the datepicker to do some validation on it.

However, when I enter the first digit of the date, for example a 1, the datepicker already assumes it's a valid date. It parses it into the date 1 January 2001. The date picker also fills the model with this incorrect date.

Because I use that date in a function that is called with a ng-change function this causes unwanted behaviour.

Is there something I'm missing, or is this a bug?

PS: this bug also happens in the demo.
http://angular-ui.github.io/bootstrap/#/datepicker#datepicker

@bolemeus
Copy link
Author

I have an addition to this...

I'm using the following format 'dd-MM-yyyy'.
When I enter the following string in the field... '1-12-2014', the datepicker ignores the format, and turns it into 12 January 2014.

This also happens in the demo when I set the format to dd.MM.yyyy and enter 1.12.2014

@hewstone
Copy link

hewstone commented Feb 6, 2015

+1. I am having the same problem. Adding a $formatter to try to change it to the correct value does not help because the $modelValue and the $viewValue are the same so we can't determine the input the user entered.

@jmayday
Copy link

jmayday commented Feb 10, 2015

I think I understand your problem @bolemeus. I also find default behaviour of datepicker not only annoying but just incorrect. I'll prepare some code/example at the evening and let you know.

@jmayday
Copy link

jmayday commented Feb 10, 2015

Hi again. I just created a plunker with newest version of angularjs and ui-boostrap (0.12.0) - http://plnkr.co/edit/yNuSZPiQYFn0Zy2COPdA
It seems like I'm not able to recreate your problem @bolemeus (typing just '1' as date doesn't put any valid date in model).

@jmayday
Copy link

jmayday commented Feb 11, 2015

I was hoping it's fixed but I checked once again and unfortunately it's still broken.

I have to admit it works fine under Firefox, but not udner Chrome (couldn't check it under IE). So I'll prepare some code and let you know anyway.

@jmayday
Copy link

jmayday commented Feb 11, 2015

#3294

@karianna karianna removed the PRs plz! label Feb 12, 2015
@wesleycho wesleycho added this to the 0.13.0 milestone Mar 24, 2015
@karianna
Copy link
Contributor

@wesleycho - this could be moved to 0.13.x?

@bartoszbobin
Copy link

Problem is in 2nd condition:
https://github.com/angular-ui/bootstrap/blob/master/src/datepicker/datepicker.js#L591

new Date('1');

FF 37.02: Date {Invalid Date}
Chrome 42: Mon Jan 01 2001 00:00:00 GMT+0100 (Central European Standard Time)
IE 11: [date] Invalid Date[date] Invalid Date

I expect from user date in provided format.

@jmayday
Copy link

jmayday commented May 7, 2015

@bartoszbobin this behaviour was already described. Have a look at plunker (link provided in my previous post)

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

6 participants