soulim / ember-cli-bootstrap-datepicker

Datepicker component for Ember CLI
http://sul.im/ember-cli-bootstrap-datepicker
MIT License
68 stars 57 forks source link

Binding value to momentjs object does not work #75

Open atonse opened 8 years ago

atonse commented 8 years ago

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 commented 8 years ago

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.