vue2-datepicker icon indicating copy to clipboard operation
vue2-datepicker copied to clipboard

[Feature request] Populate first date of week when selecting a week

Open acirinelli opened this issue 3 years ago • 1 comments

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).

CleanShot 2021-07-14 at 17 47 38

acirinelli avatar Jul 15 '21 00:07 acirinelli

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)
      }
    }
  }

}

mengxiong10 avatar Jul 15 '21 11:07 mengxiong10