nathanreyes / v-calendar

An elegant calendar and datepicker plugin for Vue.
https://vcalendar.io
MIT License
4.36k stars 848 forks source link

How can I disable past hours? #916

Open tahademirer opened 3 years ago

tahademirer commented 3 years ago

Hi! I'm using your great component in 24 hours mode. How can I disable the hours of day which are passed? Thanks!

meeshoogendoorn commented 3 years ago

@tahademirer do u already have found a solution for this problem? I need to disable some hours to. Because when the store is closed the hours needs to be hidden or disabled.

shuvikash commented 2 years ago

const now = this.$moment();

validHours(hour, dateParts) { if(!dateParts.date) { return false } const selectedDate = this.$moment(dateParts.date); if(selectedDate.isSame(this.now, 'day')) { return hour > this.now.hour(); } return hour; }

And pass this function as attribute to date picker as below:

<date-picker mode="dateTime" :minute-increment="30" trim-weeks :min-date="new Date()" :valid-hours="validHours"