Home > Back-end >  Can today's date be disabled in <v-date-picker>?
Can today's date be disabled in <v-date-picker>?

Time:01-31

I'd like to disable today's date and all dates after. I managed to disable every day after today so far.

<v-date-picker>

v-model="dateTo"
@input="menuTo = false"
:disabledDates="date.getDate()"
:max="new Date().toISOString().substr(0, 10)"

I tried :max, :min, and several methods allowing "<=" and ">=" options when returning the date. I'm still only able to disable dates before or after today, but not today.

CodePudding user response:

Just use :min="tomorrow"?

data() {
    const today = new Date()
    return { tomorrow: new Date(today.getFullYear(), today.getMonth(), today.getDate()   1)
  }
}

Or use the :allowed-date prop to allow everything except for today:

<v-date-picker :allowed-dates="allowedDates" />

methods: {
  allowedDates(date) {
    return !isToday(date)
  }
}

CodePudding user response:

<template>
  <v-date-picker v-model="dateTo" :max="maxDateAllowed"></v-date-picker>
</template>


computed: {
  maxDateAllowed() {
    const d = new Date()
    const endDate = new Date(d.getFullYear(), d.getMonth(), d.getDate() - 1);

    return endDate.toISOString().slice(0,10)
  }
}
  • Related