vue2-datepicker
vue2-datepicker copied to clipboard
[Feature request] Populate first date of week when selecting a week
What problem does this feature solve? Allow the user to select a week, but populate the input with the first date of the week rather than the date that was clicked on.
What does the proposed API look like? User clicks on the row of any week, and then the input changes to the first day of the week when type="week". Format would match the formatting provided by the user.
I was able to create my own formatter on week selection using momentFormat, such as this:
momentFormat: {
// Use moment.js instead of the default to format date instead of week number
stringify: (date) => {
return date ? moment(date).subtract(1, 'days').startOf('week').add(1, 'days').format('L') : ''
},
//[optional] String to Date
parse: (value) => {
return value ? moment(value, 'L').toDate() : null
}
}
But I cannot figure out how to load an initial starting week date into the input using v-model (on initial page load).
You can use value
and input
to replace v-model
<datepicker :value="date" @input="handleChange" />
export default {
data: {
return {
date: new Date()
}
}
methods: {
handleChange(date) {
if (date) {
this.date = startOfWeek(date)
}
}
}
}