Chen Kinnrot
Chen Kinnrot

Reputation: 21025

Sproutcore + handlebars + jquery-ui - how to make a datepicker from an input generated by handlebars

The problem is that the doc.ready fires before handlebar finish generating the inputs jquery ui needs to set the date picker on.

Is there a better event?

Upvotes: 0

Views: 511

Answers (1)

Veebs
Veebs

Reputation: 2388

Here's some code that I used for jQuery Data Picker with my SC2 demo app (Chililog)

App.MyField = App.TextBoxView.extend(App.CriteriaFieldDataMixin, {
    valueBinding: 'App.pageController.fromDate',
    name: 'fromDate',
    placeholder: 'yyyy-mm-dd',
    disabledBinding: SC.Binding.from('App.pageController.isSearching').oneWay().bool(),

    /**
     * Attach date picker to text box
     */
    didInsertElement: function() {
      this._super();
      this.$().datepicker({ dateFormat: 'yy-mm-dd' });
    }
})

Use the didInsertElement event to attach the datepicker. This event fires after the DOM element has been inserted.

Upvotes: 2

Related Questions