wakirin / Litepicker

Date range picker - lightweight, no dependencies
MIT License
896 stars 132 forks source link

Dynamic minDays (based on ranges) #273

Open sitenzo opened 2 years ago

sitenzo commented 2 years ago

Is your feature request related to a problem? Please describe. I really like LitePicker. and I'm trying to set dynamic "minDays" but don't know where to start.

Describe the solution you'd like I really like to the "minDays" to accept array with "[from,to,nights] and option for default.

Describe alternatives you've considered Writhing this function in lockdaysfilter but don't know where to start.

Additional context Example code can be found here : https://jsfiddle.net/xkLztgdy/

- Update 1 If i look at the source i think the solution would be a implementation of the following code calendar.ts#L370-L383 on a event with something like this and a date check, Now i need to figure out which event en how to best implement this.

sitenzo commented 2 years ago

I think i found the solution to my problem. With following code click here for jsfiddle

This will probably not be the best solution, but if it works it ain't stupid

    picker.on('preselect', (date1, date2) =>{
     if(!date2)
      {
        Found = false;
        jQuery(property.cnigts).each(function(index,cnigts){     
          if(date1.isBetween(new Date(cnigts[0]),new Date(cnigts[1])) == true)
          {
            console.log('temp minDays');
            picker.options.minDays = cnigts[2];
            picker.setDate(date1.timestamp()); // else ui will lag behind
            Found = true
          }     
        });

        if(Found === false && picker.options.minDays != window['nights'+property.number])
        {
          console.log('default minDays');
          picker.options.minDays = window['nights'+property.number];
          picker.setDate(date1.timestamp()); // else ui will lag behind
        }
      }
    });