Skip to content

Instantly share code, notes, and snippets.

@BlakeWilliams
Last active December 15, 2015 21:19
Show Gist options
  • Save BlakeWilliams/5324726 to your computer and use it in GitHub Desktop.
Save BlakeWilliams/5324726 to your computer and use it in GitHub Desktop.
Custom Ember view for the jQuery PickADate plugin.
App.PickADate = Ember.View.extend({
attributes: ['monthsFull', 'monthsShort', 'weekdaysFull', 'weekdaysShort',
'monthPrev', 'monthNext', 'showMonthsFull', 'showWeekdaysShort', 'today',
'clear', 'format', 'formatSubmit', 'hiddenSuffix', 'firstDay', 'monthSelector',
'yearSelector', 'dateMin', 'dateMax', 'datesDisabled', 'disablePicker'],
events: ['onOpen', 'onClose', 'onSelect', 'onStart'],
attributeBindings: ['type', 'value', 'placeholder'],
type: 'text',
tagName: 'input',
classNames: 'pickadate',
didInsertElement: function() {
var options = {}
var self = this
this.get('events').forEach(function(event) {
var callback = self[event];
if(callback) {
callback.call(this);
}
});
this.get('attributes').forEach(function(attr) {
if (self[attr] != undefined) {
options[attr] = self[attr];
}
});
var onSelectCallback = options.onSelect
options.onSelect = function() {
Ember.set(self, 'value', this.getDate(true));
if (onSelectCallback) {
onSelectCallback.call(this);
}
};
this.$().pickadate(options);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment