More data type fixes for <tailbone-datepicker>

traditionally the caller has always dealt with string values only, so
the component should never emit events with date values, etc.
This commit is contained in:
Lance Edgar 2024-05-07 18:20:26 -05:00
parent d607ab2981
commit 28fb3f44a7

View file

@ -27,20 +27,14 @@ const TailboneDatepicker = {
}, },
data() { data() {
let buefyValue = this.value
if (buefyValue && !buefyValue.getDate) {
buefyValue = this.parseDate(this.value)
}
return { return {
buefyValue, buefyValue: this.parseDate(this.value),
} }
}, },
watch: { watch: {
value(to, from) { value(to, from) {
if (this.buefyValue != to) { this.buefyValue = this.parseDate(to)
this.buefyValue = to
}
}, },
}, },
@ -61,13 +55,16 @@ const TailboneDatepicker = {
}, },
parseDate(date) { parseDate(date) {
if (typeof(date) == 'string') {
// note, this assumes classic YYYY-MM-DD (i.e. ISO?) format // note, this assumes classic YYYY-MM-DD (i.e. ISO?) format
var parts = date.split('-') var parts = date.split('-')
return new Date(parts[0], parseInt(parts[1]) - 1, parts[2]) return new Date(parts[0], parseInt(parts[1]) - 1, parts[2])
}
return date
}, },
dateChanged(date) { dateChanged(date) {
this.$emit('input', date) this.$emit('input', this.formatDate(date))
}, },
focus() { focus() {