nathanreyes / v-calendar

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

[Question] Disable end date based on start date? #1428

Open tommycrumrine opened 9 months ago

tommycrumrine commented 9 months ago

Love this plugin! Thank you for all the work you've put into it.

The requirements for our datepicker are relatively complex, and I've been so far unable to fully implement what we need using v-calendar for date range selection. Specifically, we want to be able to disallow specific dates (not necessarily the min/max date) based on the first date selected. For example, maybe Dec 30 is a valid start date but not a valid end date. Jan 1 is a valid end date but not a valid start date. Jan 2 is valid end date if Dec 30 is selected as the start date but not if Dec 29 is selected as the start date. Does that make sense and is this level of reactivity possible?

What I've attempted so far:

  1. using an array of disabled-dates, and keying off the currently selected dragValue using the drag event. This sorta works, but doesn't work when the start date is not a valid end date. E.g. I click Dec 30 to start, but need to select at least 2 days in the range so now Dec 30 is added to disabled-dates. When I click a valid end date, it seems to not think that the selected range is valid and doesn't update (I'm guessing because the start date is now invalid?)

  2. Using attributes and providing { key: 'disabled', content: { class: 'disabled' }, dates: disabledDates }. This almost works, but once a date is selected its content computed property on the CalendarDay component for the start date has { class: undefined, key: "select-drag-content", ... } appended to it (the custom disabled attribute is still there) but the class is pulled from the last element rather than merging, so I don't get my disabled class.

  3. Using the day-content scoped slot. This mostly gets me there, but the built in class: this.dayContentClass, style: this.dayContentStyle are not exposed to the slot, so things look kind of goofy and I lose a bunch of the default functionality that I still want, e.g. the minDate maxDate needs to be reimplemented. I could probably get a version of this to work, but hate that I'd have to reimplement stuff that is otherwise workign fine.

Am I missing something obvious or is this just outside of the scope for this packages functionality?