Atomic Spin has a great article on setting up Pikaday with an Ember.TextField
view.
However, since I'm using Ember Data with some date
attributes, I needed to actually use a Date
object rather than a formatted date string. Here's what I came up with after adding a few things to their example:
There were a couple things I had to add for this to work:
- I'm using the moment.js library to allow
MM/DD/YYYY
formatting. - I format the existing date in the
didInsertElement
event handler. - Rather than binding the attribute directly to the
value
, I'm using adate
binding instead. This gives me the chance to parse a formatted date before setting the attribute. - Two-way binding to the date:
- The
updateDate
function, which observesvalue
, directly sets thedate
to the parsed value. - The
updateValue
function, which observesdate
, updates thevalue
with the formatted date.
- The