mymth / vanillajs-datepicker

A vanilla JavaScript remake of bootstrap-datepicker for Bulma and other CSS frameworks
MIT License
718 stars 147 forks source link

[feature] [request] Date Range Picker Option: MinDateRange #153

Open jagottsicher opened 11 months ago

jagottsicher commented 11 months ago

the vanillajs-datepicker is awesome.

I'd like to request a feature.

Imagine a hotel using vanillajs-datepicker's the date range picker to let customers choose date ranges for their stay. with minDate option I can prevent people from booking something in the past as long time travel is not invented, but the date-range-picker allows to set a minDate range of 1 day. But hotels usually allow booking a room overnight only - that means start date and end date cannot be the same!

That's a problem in wrapping applications. I have to let the user choose dates and then evaluate the results after submitting. That makes no sense. Better was to have an option:

MinDateRange in Days

Which allows only to choose a minimum number of days after and render that every time the start date is chosen. the end date needs to be set automatically to the minDate + MinDateRange and exclude to choose a end date same as start date.

Or did I overlook an option to achieve that the user can choose a date range of minimum 2 days?

mymth commented 11 months ago

I'd like to make sure If my understanding that this is for making DateRangePicker able to work like this https://codepen.io/mymth/pen/eYQjBYm is correct.

Could you please check the quick demo above? Thanks.

jagottsicher commented 11 months ago

Thanks!

That's exactly the intended behavior I am suggesting!

I tried some different ranges for const minRangeSpan = 5; and it works smootly. Could not test though if it interfers with a min date or max date if set.

Actually I use the the vanillajs-datepicker in one of my courses because it's so clean and easy to implement. But I had to use a "clumpsy" workaround.

If this features will be implemented I will for sure make use of it.

mymth commented 11 months ago

Thank you for confirming. Ah, yeah, I omitted min/maxDate part from the "quick" demo because considering how to implement seemed to be needed. Anyway, I'll add this feature in a near future version.