tailbone/tailbone/static/js/tailbone.buefy.datepicker.js
Lance Edgar 6c3722737d OMG so many Buefy things...and much to be done yet it seems
these changes are all with Buefy "forms" support in mind.  hopefully didn't
break any legacy/jquery stuff... and yeah, lots more left to do still for the
sake of Buefy forms
2019-05-22 15:31:23 -05:00

50 lines
1.3 KiB
JavaScript

const TailboneDatepicker = {
template: [
'<b-datepicker',
'placeholder="Click to select ..."',
`:name="name"`,
`:id="id"`,
'editable',
'icon-pack="fas"',
'icon="calendar-alt"',
':date-formatter="formatDate"',
':date-parser="parseDate"',
'@input="dateChanged"',
'>',
'</b-datepicker>'
].join(' '),
props: {
name: String,
id: String,
},
methods: {
formatDate(date) {
// just need to convert to simple ISO date format here, seems
// like there should be a more obvious way to do that?
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
month = month < 10 ? '0' + month : month
day = day < 10 ? '0' + day : day
return year + '-' + month + '-' + day
},
parseDate(date) {
// note, this assumes classic YYYY-MM-DD (i.e. ISO?) format
var parts = date.split('-')
return new Date(parts[0], parseInt(parts[1]) - 1, parts[2])
},
dateChanged(date) {
this.$emit('input', this.formatDate(date))
}
}
}
Vue.component('tailbone-datepicker', TailboneDatepicker)