2

I have the mulitdatespicker, and I need to disable ALL dates except those that are every 2 weeks from the "defaultDate".

So if the current day is set to thursday 6th May, I need to disable all days before it, then all the days up to Thurs 20th May (2 weeks from the 6th). Then disable 2 weeks again up to 3rd June... (2 weeks from the 20th) etc.

So the only dates selectable are every 2 weeks from the defaultDate.

jQuery('.multidatepicker').multiDatesPicker({
    dateFormat: "d M yy", 
    defaultDate: '6 May 2021',
    maxDate: 72,
    minDate: new Date(),
    addDisabledDates: ??? //Do I add something here?
}); 

user2115227
  • 147
  • 2
  • 9
  • 24

1 Answers1

2

you could do that: push disabled dates in an array

var defaultDate = new Date("6 May 2021");
var datedeb = new Date(defaultDate);
var maxDate = 72;

var arDate=[];
var enable = false;

for(var i = 1; i <maxDate; i++)
{
    enable = i % 14 == 0;
    var newdate = new Date(datedeb.setDate(datedeb.getDate() + 1));
    if(!enable)arDate.push(newdate);  

}

jQuery('.multidatepicker').multiDatesPicker({
    dateFormat: "d M yy", 
    defaultDate: defaultDate,
    maxDate: maxDate,
    minDate: defaultDate,
 addDisabledDates: arDate
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css" rel="stylesheet"/>

<script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script>
<link href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css" rel="stylesheet"/>
<div class ="multidatepicker" id="mdp-demo"></div>
Frenchy
  • 16,386
  • 3
  • 16
  • 39
  • Thanks for this but it's not QUITE what I needed. It seems that it disables dates fro 2 weeks, then the next 2 weeks are available. Maybe I didn't explain: The ONLY dates that should be available would be the start date, then the day 2 weeks from that start date, then the day 4 weeks from that start date, then the date 6 weeks from the start date, etc. – user2115227 May 03 '21 at 19:26
  • So Start Date = Thurs 6th May. ALL dates disabled apart from Thurs 6th may, Thurs 20th May, 3rd June, 17th June, etc – user2115227 May 03 '21 at 19:29
  • Great thank you. So If I wanted to change this to once every 4 weeks, rather than 2, I would change enable = i % 14 == 0; to enable = i % 28 == 0;? – user2115227 May 04 '21 at 06:34
  • yes exactly, you play with the value modulo, 28 is 4 weeks – Frenchy May 04 '21 at 06:37
  • Thanks. This is almost perfect, however your code allows for the 4th and 5th to be selectable also. It should only be 6th, 20th, 3rd, 17th, etc – user2115227 May 04 '21 at 07:39
  • Its not my code, you have set minDate to currend date, so the 4th and 5th are enabled, change minDate to your defaultDate, (its the modification i have done) and these dates will be disabled – Frenchy May 04 '21 at 08:12