jquery multidatepicker min date disturbs datepickers UI

506 Views Asked by At

Concept : I am creating a calendar of one year. say 01-01-2017 to 31-12-2017.
Issue : when i set min date to 08-06-2017 then datepicker goes rearranged and it becomes a datepicker of 01-06-2017 to 31-05-2018 what i need is it should start from 1 jan 2017 and ends with 31 dec 2017

js code :

$('#generate_sampling .full-year').multiDatesPicker({
    addDates: dates,
    numberOfMonths: (samplingStatus=="EDIT" ? [3,4] : [6,4]),
    minDate : startDate,
    maxDate : endDate,
    defaultDate :  '01/30/'+(year == '' ? '2017' : year),
}); 
2

There are 2 best solutions below

0
Rahul Dani On BEST ANSWER

Here i managed to stop rearrangement of dates. i added some conditions under beforeShowDay and commented my min and max date parameters

$('#generate_sampling .full-year').multiDatesPicker({
        addDates: dates, // array of dates
        numberOfMonths:  [3,4] ,
        /*minDate : startDate,
        maxDate : endDate,*/
        defaultDate :  '01/30/'+(year == '' ? '2017' : year),

        beforeShowDay: function(dateStamp) {
            var className="";
            if(dateStamp < new Date(startDate) || dateStamp > new Date(endDate)){
                className =" ui-datepicker-unselectable ui-state-disabled "
            }
            var title = "Disabled";
            return [true, className ,title]; // title will be displayed as tooltip
        }
});

In case beforeShowDay is not working please check your multidatepickers core js file. this below line must be commented . uncomment it. it will work.

this.multiDatesPicker.originalBeforeShowDay = options.beforeShowDay;

Thank you!

2
Amal On

Hope this helps

$('.full-year').multiDatesPicker('destroy');

Destroy the Datepicker before you set minDate

DEMO