soulim / ember-cli-bootstrap-datepicker

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

Oberservers cause type errors on Ember 1.13.2 #41

Open codebruder opened 9 years ago

codebruder commented 9 years ago

Uncaught TypeError: Cannot read property 'datepicker' of undefined is caused when you handle the observed properties (language, startDate, endDate) except of value on Ember 1.13.2. Ember triggers the _didChangeLanguage(), _updateStartDate() and _updateEndDate() methods before the element is rendered and therefore this.$() is undefined and the code breaks.

works: {{bootstrap-datepicker value=someDate placeholder="do it" class="form-control"}}

breaks: {{bootstrap-datepicker value=someDate language="de" placeholder="do it" class="form-control"}}

To fix this you have to declare the oberserved properties as properties. Like this:

// datepicker-support.js 
import Ember from 'ember';

export default Ember.Mixin.create({
  mustUpdateInput: true,
  value: null,
  // add the observed properties
  language: null,
  startDate: null,
  endDate: null,

  // ... other methods

});

I'm certain there is a more elegant solution, but this quick fix did it for me. I extended your component in my own component and it works like a charm. Nonetheless good work and a useful plugin!

aldhsu commented 9 years ago

@BW-AdrianG I tried your fix. While it works for the startDate and endDate it throws an error on the language on initialize. The base jQuery bootstrap component complains about null.split on the language.

I got around this by setting a default EN language.

I haven't had a lot of experience with 1.13 yet so I will reserve my judgement on what could be a way forward to support 1.13.

srisonti commented 9 years ago

I'm running into this issue as well, and I'm not entirely sure why. I'm using the latest master branch from the npm repo (v0.5.3), but I'm getting the Uncaught TypeError: Cannot read property 'datepicker' of undefined error.

I'm currently using ember 1.13.3. Any idea what the issue might be? Thanks for building this awesome plugin!

soulim commented 9 years ago

Recently released v0.5.4 solves this issue. Please install it from the npm repository. Thank you for feedback! :heart:

srisonti commented 9 years ago

Thanks for getting back to both of my comments so quickly! you rock :+1: