Last active
August 4, 2016 23:02
-
-
Save davelowensohn/70501e5a97b385bcfac6 to your computer and use it in GitHub Desktop.
Ember Datepicker example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import moment from 'moment'; | |
const { computed } = Ember; | |
export default Ember.Component.extend({ | |
classNames: 'date-picker', | |
inputDate: null, | |
computedDate: computed('inputDate', { | |
get() { | |
if (this.get('inputDate')) { | |
var formattedDate = moment.utc(this.get('inputDate')).format('YYYY-MM-DD'); | |
return formattedDate; | |
} else { | |
return; | |
} | |
}, | |
set(key, value) { | |
var formattedDate = moment.utc(value); | |
if (formattedDate.isValid()) { | |
this.set('inputDate', formattedDate.toDate()); | |
} else { | |
this.set('inputDate', null); | |
} | |
return value; | |
} | |
}), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import moment from 'moment'; | |
export function formatDate(params/*, hash*/) { | |
var inputDate = params[0]; | |
var formattedDate = moment.utc(inputDate).format('YYYY-MM-DD'); | |
return formattedDate; | |
} | |
export default Ember.Helper.helper(formatDate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment