Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js - ember-pikaday not allowing preset date

I am trying to create a datepicker in ember.js using the ember-pikaday addon. The datepicker should have a date in it when it is displayed. So, I added the following code to my template:

{{pikaday-input value=rental.date format="MMMM Do YYYY" yearRange="2016" useUtc=true}}

However, even though I specify the value as rental.date, the input is blank. I know that the value of rental.date is not null because when I set the placeholder to rental.date, the placeholder's date is correct.

like image 836
user2367593 Avatar asked Dec 19 '25 05:12

user2367593


1 Answers

The problem with your case is due to the fact that you are passing a momentjs object to ember-pikaday directly. Instead of passing the momentjs object directly just create a computed property called as follows on your owner component:

  rentalDate:Ember.computed('rental.date', function() {
      return this.get('rental.date').toDate();
  }),

and perform binding to rentalDate. ember-pikaday does not handle momentjs object passed in by itself, just extract the actual javascript date object via toDate() as shown in code snippet above. Just for clarification you can also pass formatted string to ember-pikaday such as "25/05/2016", "2016.05.25", etc. It will also handle such string values properly.

like image 188
feanor07 Avatar answered Dec 21 '25 18:12

feanor07



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!