Skip to content

datepicker: Add support for passing IOS8601 strings to datepicker regardless of the DateAdapter #6265

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

Closed
mahmood-sajjadi opened this issue Aug 4, 2017 · 11 comments · Fixed by #7091
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@mahmood-sajjadi
Copy link

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Initial value in text field is empty string and Date picket required an input text field which means should accept empty string as not defined value, or is user want to remove value, should be able to remove text field value

What is the current behavior?

in master code
in this PR : 8bb54ca
in this file:
https://github.com/angular/material2/blob/master/src/lib/datepicker/datepicker-input.ts#L119

an empty string is not an acceptable value and it is raising the following error:
Datepicker: value not recognized as a date object by DateAdapter.

What are the steps to reproduce?

Just add
formControlName="birthdate"
to input field in datepicker and sround it by formGroup

this is plunker example:
http://plnkr.co/edit/bhswcOgSB36yqD6Yr8nF?p=preview

please open chrome console to see the warning an error

What is the use-case or motivation for changing an existing behavior?

Using datepicker in form group

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

angular 4.3.2
material 2.0.0-beta.8-5967f6e

Is there anything else we should know?

It was working fine before that PR becuse the condition was
if (!value)
which is working as expected with empty string

@mmalerba
Copy link
Contributor

mmalerba commented Aug 4, 2017

We no longer support setting the value of the datepicker to something that is not a Date object, such as a string. If you want the datepicker to start off empty just use null instead of '': http://plnkr.co/edit/2mvkFihkfvEeX2Yhkmuw?p=preview

@mmalerba mmalerba closed this as completed Aug 4, 2017
@nicholasjativa
Copy link

@mmalerba what would be a solution, then, in an instance where we previously would get a Date string from somewhere (like Firebase) and we try to set the value of a datepicker using setValue(aDateString)? I guess its possible to do setValue(newDate(aDateString)), however, that wouldn't work when copying an entire object (from a backend) to a formGroup using setValue(anObj). Thanks.

@mmalerba
Copy link
Contributor

@nicholasjativa Hmm interesting I had not considered that case. The reason I removed the ability to use strings is because it was possible to put locale-sensitive strings in your code, e.g. 1/2/2017. Currently you would have to transform the response object to change the fields to actual Date objects. I could maybe add back the ability to accept ISO 8601 strings only

@nicholasjativa
Copy link

@mmalerba a fix like that would be great.

@mmalerba
Copy link
Contributor

mmalerba commented Sep 1, 2017

Reopening this to track the fix discussed above

@mmalerba mmalerba reopened this Sep 1, 2017
@mmalerba mmalerba added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Sep 1, 2017
@johnrjj
Copy link

johnrjj commented Sep 1, 2017

Allowing ISO 8601 strings by default would be extremely useful

@another-guy
Copy link

What is the official decision on whether ISO8601 based dates will or will not be supported?

At the moment, I have to use a custom DataAdapter that seems to do the job, but should I even focus on that or wait till next version of the angular/material2? Gist with the custom adapter, please feel free to review: https://gist.github.com/another-guy/adc2d9d731af7693fdbfab21b1e227a9#file-iso8601datestringadapter-ts

Personally, I believe that using Date as the first class object is not quite right for datepicker since it represents a DateTime object rather than Date only.

@mmalerba
Copy link
Contributor

@another-guy I will add the ability to pass ISO8601 strings to the datepicker and have it convert them into the appropriate object to for the DateAdapter but there are no current plans to add a ISO8601DateAdapter

@another-guy
Copy link

@mmalerba that makes sense and I didn't really expect that snippet to get to the code base (since it has a dependency on external project). What what important is some kind of native support of ISO8601. Thanks!

Is there a tracking issue I could subscribe to regarding the ISO8601 support?

@mmalerba
Copy link
Contributor

This is actually the right issue, let me just rename it to make that more obvious

@mmalerba mmalerba changed the title DatePicker Latest changes raising an error datepicker: Add support for passing IOS8601 strings to datepicker regardless of the DateAdapter Sep 14, 2017
@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 7, 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.

5 participants