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

FIX - DatePicker now accepts input value fields with the right formatDate #1855

Closed
wants to merge 5 commits into from

Conversation

getuliojr
Copy link

I noticed that when you type the date in a input field instead of picking it. It was not parsing it right through the dateFormat informed, saw this problem on some issues: (#956, #1107, #1430).

This Fix will parse the input value typed with the dateFormat informed and pick it on the datepicker if the date is valid. Hope it can help others. Working fine for me now when dateFormat is 'dd/MM/YYYY'. I can type date in this format and it will pick it right in the datepicker.

I noticed that when you type the date in a input field instead of picking it. It was not parsing it right through the dateFormat informed, so I fix it.

This Fix will parse the input value typed also using the dateFormat.
@@ -372,13 +372,20 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
ngModel.$setValidity('date', true);
return viewValue;
} else if (angular.isString(viewValue)) {
var date = new Date(viewValue);
if (isNaN(date)) {
var dateStr = dateFilter(viewValue, dateFormat);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it uses the dateFilter service to format the "Date typed (string)" in the format the user is expecting.

Fixing comparison to use === instead or ==
if (dateStr === undefined)
Another fix, so the dates can be typed in the format: February, 24 2014 and not 99/99/9999 anymore
Just some fix to pass jshint check and a little optimization. Now it already parse the string and then if it is in the formar 99.99.9999 parses again.
Trying to fix JSHint Errors
@bekos
Copy link
Contributor

bekos commented Feb 28, 2014

@getuliojr Thx for your time on this one, but your PR handles a specific use case, so it cannot be merged, as we are looking for a more general solution to this problem. Additionally, almost all PRs must have an accompanying test case.

@bekos bekos closed this Feb 28, 2014
@jcstritt
Copy link

jcstritt commented Nov 4, 2014

Eight months later, this bug is already here ... bekos, why are you closed this issue ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants