Hey everyone,
I need to know what JavaScript to use in order to hide / gray out a Form's calendar field's holidays and weekends. Has anyone already done this? I'd love to plug and play the code for it if so, thanks!
- Ryan
Hey everyone,
I need to know what JavaScript to use in order to hide / gray out a Form's calendar field's holidays and weekends. Has anyone already done this? I'd love to plug and play the code for it if so, thanks!
- Ryan
Hi Ryan,
Here is a demo for Forms 10.2 and above. You need to set date field with CSS class 'checkDate' and manually update the "holidays" in script to contain all holidays you want to define.
$(document).ready(function(){ var holidays = ["2017-12-25", "2018-01-01"]; function isCorrectDate(n) { var date = jQuery.datepicker.formatDate('yy-mm-dd', n); if (holidays.indexOf(date) != -1) { return false; } else { var t = n.getDay(); return (t!=6 && t != 0); } } function checkDate(n) { return[isCorrectDate(n),""]; } function checkField(input, inst) { if ($(input).closest('li').hasClass('checkDate')) { $(input).datepicker("option", {beforeShowDay: checkDate}); } } $.datepicker.setDefaults( {beforeShow: checkField} ); window.Parsley.addValidator('noweekend', { validateString: function(value) { console.log(value); return isCorrectDate(new Date(value)); }, messages: { en: 'Not valid date.' } }); $('.checkDate input').attr('data-parsley-noweekend',''); })
Hi @████████,
We have a similar application and use of the script you provided above, except we were looking to restrict it to only Mondays, while restricting holidays. I was able to make it work with the following (inelegant) change to line 9 of your code:
return (t!=0 && t != 2 && t!=3 && t!=4 && t!=5 && t!=6);
This works, but I'm looking to take it one step further, and have it allow Tuesdays to be chosen if the holiday falls on a Monday.
Is this something that is doable with out putting you through the wringer?
Thanks
Hi Evan,
You can try update the isCorrectDate function to this:
function isCorrectDate(n) { var date = jQuery.datepicker.formatDate('yy-mm-dd', n); var t = n.getDay(); if (t == 1) { return (holidays.indexOf(date) == -1); } else if (t == 2) { var yesterday = new Date(n); yesterday.setDate(n.getDate() - 1); var yesterdayDate = jQuery.datepicker.formatDate('yy-mm-dd', yesterday); return (holidays.indexOf(yesterdayDate) != -1); } return false; }
Thanks @████████!
That worked wonderfully! (And is much nicer looking than what I attempted)
Thanks!
Hi, we have supported configuring holiday calendars on Forms 12.
You can see other changes from: Laserfiche 12 Changelog
Get Laserfiche Forms 12 package from: Laserfiche 12 - Downloads