-
Notifications
You must be signed in to change notification settings - Fork 21
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
<Form.Input @type="datetime-local" /> woes #84
Comments
This is interesting. I'm not sure if it makes sense to handle that automatically. It really depends on how you are handling the data. For example, if you're using Ember Data, it might make sense, but if you are not, then this could be a bad assumption to transform the data into a Date object. For these cases where we want to handle the data differently than the default browser behavior, I would not use the Changeset From components, instead, I would use FormInput directly where I can control the onChange, onInput etc. Does this make sense? |
This one is old. Hope I remember all my thoughts.
This sounds like you would lose the changeset validation though? If not, could you give an example that would work?
Yes, I do agree with that one. I wanted to figure out whether there is some one-size-fits all solution. Or whether this might be a note in documentation to help the newcomers? |
And for my future self a version without using @attr('date') issuedAt;
get issuedAtString() {
return this.issuedAt.toISOString().replace(/:\d+.\d+Z$/, '');
}
set issuedAtString(newDate) {
this.issuedAt = new Date(`${newDate}:00.000Z`);
} Apparently even according to MDN there is no nice way to convert
And in reverse MDN warns against different browsers trying to parse strings into dates with different levels of success:
|
This really goes to the weirdness of how datetime-local works, but maybe internal wiring to make it work out-of the box would be a good idea.
The problem
Following code will not work:
The problem is that respective HTML element will return value as string that has format as follows:
2017-06-01T08:30
. Which then does not get translated properly from/toDate()
used inember-data
. Also I believe this will make problems with validation.Proposed solution
<Form.Input>
receives@type='datetime-local'
it should do the conversion automagically.Workaround
In case anyone wonders, there is pretty simple manual solution for this:
The text was updated successfully, but these errors were encountered: