Dissallow date(s)

nycreate

Member
Wizard Hugh helped me out with this funky bit of JS we use on an old Fabrik site..

JavaScript:
function disallowDate(cal, date) {
   var today = new Date;
   var three_days = 1000 * 60 * 60 * 24 * 1;
dayDiff = date.getTime() - today.getTime();
   if (dayDiff < three_days) {
      return true;
   }

   date_array = [ '16-12-2016', '17-12-2016', ];
   for (i=0; i < date_array.length; i++) {
       if (date_array[i] == date.format('%d-%m-%Y')) {
          return true;
      }
   }
   return false;
}

To restrict some calendar dates on the calendar pop up.. This doesn't seem to work in the latest version of fabrik. Can someone help me out with this to get it working in the latest version please? Its currently a separate js file.

The ideal would be able to block
Dates less than 3 days away
All weekends
bank holidays (a simple array)
All dates more than 1 month away or dates not in this year

I've tried messing with the wiki examples but JS is just not a strength of mine.

Thanks in advance.
 
Remove the 'cal' from the args so it's just (date), then in the "Allow date function" do ..

Code:
var result = disallowDate(date);

That is assuming that function is in a from_X.js file, or somewhere else that includes it on your page.

-- hugh
 
Brilliant, Thanks Hugh!..

I've cleaned it up a bit following another one of your other examples and blocked +30 days aswell..

For anyone else that may need this is the code I've used to block out weekends, bank holidays any days less than 3 days or more than 30 days away...
added as a separate js file..

JavaScript:
function disallowDate(date) {
   var today = new Date;
   var dayDiff = date.getDayOfYear() - today.getDayOfYear();
   if (dayDiff < 3 || dayDiff > 30) {
      return true;
   }

   date_array = ['16-12-2016', '17-12-2016', '18-12-2016', '19-12-2016', '20-12-2016', '21-12-2016', '22-12-2016', '23-12-2016', '24-12-2016', '25-12-2016', '26-12-2016', '27-12-2016', '28-12-2016', '29-12-2016', '30-12-2016', '31-12-2016', '01-01-2017', '02-01-2017', '03-01-2017', '04-01-2017', '05-01-2017', '07-01-2017', '08-01-2017', '09-01-2017', '14-01-2017', '15-01-2017', '16-01-2017', '21-01-2017', '22-01-2017', '23-01-2017', '28-01-2017', '29-01-2017', '30-01-2017', '04-02-2017', '05-02-2017', '06-02-2017', '07-02-2017', '11-02-2017', '12-02-2017', '18-02-2017', '19-02-2017', '25-02-2017', '26-02-2017', '04-03-2017', '05-03-2017', '11-03-2017', '12-03-2017', '18-03-2017', '19-03-2017', '25-03-2017', '26-03-2017', '01-04-2017', '02-04-2017', '08-04-2017', '09-04-2017', '14-04-2017', '15-04-2017', '16-04-2017', '17-04-2017', '22-04-2017', '23-04-2017', '29-04-2017', '30-04-2017', '06-05-2017', '07-05-2017', '13-05-2017', '14-05-2017', '20-05-2017', '21-05-2017', '27-05-2017', '28-05-2017', '29-05-2017', '03-06-2017', '04-06-2017', '10-06-2017', '11-06-2017', '17-06-2017', '18-06-2017', '24-06-2017', '25-06-2017', '01-07-2017', '02-07-2017', '08-07-2017', '09-07-2017', '15-07-2017', '16-07-2017', '22-07-2017', '23-07-2017', '29-07-2017', '30-07-2017', '05-08-2017', '06-08-2017', '12-08-2017', '13-08-2017', '19-08-2017', '20-08-2017', '26-08-2017', '27-08-2017', '28-08-2017', '02-09-2017', '03-09-2017', '09-09-2017', '10-09-2017', '16-09-2017', '17-09-2017', '23-09-2017', '24-09-2017', '30-09-2017', '01-10-2017', '07-10-2017', '08-10-2017', '14-10-2017', '15-10-2017', '21-10-2017', '22-10-2017', '28-10-2017', '29-10-2017', '04-11-2017', '05-11-2017', '11-11-2017', '12-11-2017', '18-11-2017', '19-11-2017', '25-11-2017', '26-11-2017', '02-12-2017', '03-12-2017', '09-12-2017', '10-12-2017', '13-12-2017', '14-12-2017', '15-12-2017', '16-12-2017', '17-12-2017', '18-12-2017', '19-12-2017', '20-12-2017', '21-12-2017', '22-12-2017', '23-12-2017', '24-12-2017', '25-12-2017', '26-12-2017', '27-12-2017', '28-12-2017', '29-12-2017', '30-12-2017', '31-12-2017', '01-01-2018', '02-01-2018', '03-01-2018',];
   for (i=0; i < date_array.length; i++) {
       if (date_array[i] == date.format('%d-%m-%Y')) {
          return true;
      }
   }

   return false;
}
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top