Bug
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
in master code
in this PR : https://github.com/angular/material2/commit/8bb54ca4565a7d55d4f74ca0af4c8e7e02efb462
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.
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
Using datepicker in form group
angular 4.3.2
material 2.0.0-beta.8-5967f6e
It was working fine before that PR becuse the condition was
if (!value)
which is working as expected with empty string
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 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.
@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
@mmalerba a fix like that would be great.
Reopening this to track the fix discussed above
Allowing ISO 8601 strings by default would be extremely useful
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.
@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
@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?
This is actually the right issue, let me just rename it to make that more obvious
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._
Most helpful comment
Allowing ISO 8601 strings by default would be extremely useful