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

Binding value to momentjs object does not work #75

Open
atonse opened this issue Apr 14, 2016 · 1 comment
Open

Binding value to momentjs object does not work #75

atonse opened this issue Apr 14, 2016 · 1 comment

Comments

@atonse
Copy link

atonse commented Apr 14, 2016

I am currently trying to edit a form and since my object is a moment.js object instead of a Date object, it's not binding to the control.

My setup:
I am currently in EDT (UTC-4).

I have a project model, with startDate and endDate – I am saving this as just a date.

With a naive implementation (Ember Data's date transform), when a date is selected, the date is then saved to the backend API without any issues. But when the date is retrieved from the API, since the time is missing from the date, it is converted to my local time, which is a day before.

To fix this, I implemented the ember data UTC transform as outlined by Tom Dale in http://blog.skylight.io/bringing-sanity-to-javascript-utc-dates-with-moment-js-and-ember-data/. This converts my date object to a momentjs object and correctly handles UTC.

While this fixed my issue with displaying dates as UTC, and I can save new bootstrap-datepicker values correctly, when I try to edit, since my date is a momentjs object, bootstrap-datepicker doesn't bind to it properly. If I convert it back to a date, datepicker binds correctly but with the wrong date (since it's UTC-4)

What's the shared community solution for this? Surely everyone deals with this?

@jelhan
Copy link
Contributor

jelhan commented Aug 15, 2016

Oh, didn't noticed yet that moment.js objects aren't supported. I would recommend a computed property: https://ember-twiddle.com/7ff74a9f6ee7028dbf712b2b02ba06b5?openFiles=controllers.application.js%2C

I guess this should be documented.

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

No branches or pull requests

2 participants