Skip to content

Instantly share code, notes, and snippets.

@Janther
Created September 4, 2015 21:59
Show Gist options
  • Save Janther/3f06a492b3554637497a to your computer and use it in GitHub Desktop.
Save Janther/3f06a492b3554637497a to your computer and use it in GitHub Desktop.
App.DatetimePickerComponent = Em.Component.extend
$picker: null
picker_format: 'dd/mm/yy'
placeholder: Em.computed.alias('format')
# Init function
didInsertElement: ->
$picker = @$('input').datepicker
dateFormat: @get('picker_format')
@set('$picker', $picker)
$picker.datepicker('setDate', @get('value')) if @get('value')
$picker.on 'change', =>
@set('value', $picker.datepicker('getDate'))
$picker.blur()
# Model Observer
datetimeChanged: (->
# get model datetime
modelDatetime = @get('value')
# get picker datetime
$picker = @get('$picker')
pickerDatetime = $picker.datepicker('getDate')
# Overwrite picker date if modelDatetime and pickerDatetime are not the same.
unless Em.isEqual(modelDatetime, pickerDatetime)
$picker.datepicker('setDate', modelDatetime)
).observes('value')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment