Ember Date Picker with Ember Data and Pikaday Mar 27

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 a date 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 observes value, directly sets the date to the parsed value.
    • The updateValue function, which observes date, updates the value with the formatted date.

comments powered by Disqus