Get ready, this one took me a minute, but it completely possible with the moment.js that's built into Laserfiche Forms. So I'll give you the code first then explain each part.
//Sets date to two business days from current date
var twoBusinessDays = addWeekdays(currentDate, 2).format('YYYY-MM-DD');
var sameDay = addWeekdays(currentDate, 0).format('YYYY-MM-DD');
function addWeekdays(date, days) {
date = moment(date);
while (days > 0) {
date = date.add(1, 'days');
//Decrease "days" only if it's a weekday.
if (date.isoWeekday() !== 6 && date.isoWeekday() !== 7) {
days -= 1;
}
}
return date;
}
//Sets Minimum Dates for datepicker
$('#Field70').on('click', function(){
if (($('#Field70-0').prop('checked') == true) || ($('#Field70-1').prop('checked') == true) || ($('#Field70-2').prop('checked') == true) || ($('#Field70-3').prop('checked') == true)){
$("#Field18").prop('min', twoBusinessDays);
$("#Field18").val(moment(twoBusinessDays).format('MM/DD/YYYY'));
}
else{
$('#Field18').prop('min', currentDateFormatted);
$('#Field18').val(moment(currentDateFormatted).format('MM/DD/YYYY'));
}
});
Ok. So if your not familiar with JavaScript the // and text is a comment. It doesn't do anything but inform you.
We'll break it into two pieces since it technically is.
//Sets date to two business days from current date
var twoBusinessDays = addWeekdays(currentDate, 2).format('YYYY-MM-DD');
var sameDay = addWeekdays(currentDate, 0).format('YYYY-MM-DD');
function addWeekdays(date, days) {
date = moment(date);
while (days > 0) {
date = date.add(1, 'days');
//Decrease "days" only if it's a weekday.
if (date.isoWeekday() !== 6 && date.isoWeekday() !== 7) {
days -= 1;
}
}
return date;
}
Ok, so the var portion is setting a variable to get the date from today + 2 (twoBusinessDays) and the current date.
The function takes the date (today) and the days (Two business and 1 business days) and uses them as "reference points". I'll try to keep the jargon to a minimum also to make my points. The if portion of it checks if today is a weekend (Saturday or Sunday) and then adds the days from there. It makes sure it only adds business days, not calendar days.
The twoBusinessDays variable (var) is where you will change it. Make it something like threeBusinessDays and change the 2 inside the parentheses on the same line to a 3. That should be all it will take to make this work if you know how to set up the rest.
The next part is where the magic actually happens. That first part just sets up needed background "magic".
//Sets Minimum Dates for datepicker
$('#Field70').on('click', function(){
if (($('#Field70-0').prop('checked') == true) || ($('#Field70-1').prop('checked') == true) || ($('#Field70-2').prop('checked') == true) || ($('#Field70-3').prop('checked') == true)){
$("#Field18").prop('min', twoBusinessDays);
$("#Field18").val(moment(twoBusinessDays).format('MM/DD/YYYY'));
}
else{
$('#Field18').prop('min', currentDateFormatted);
$('#Field18').val(moment(currentDateFormatted).format('MM/DD/YYYY'));
}
});
The first part is kind of set to my case, but can easily be changed and I'll tell you how in a bit. It says that when a field I choose (Field70 in this case) is clicked, to run the rest of the code.
From there the if statement checks which radio button (from the field I choose) is selected and reacts accordingly. If the specific radio buttons I choose are selected (checked is the JavaScript terminology) then run the little bit of code in the first "{" brackets.
That code sets the "min" value of the date field (which is how you get the jump in time) and then formats it in a way that won't mess with the Laserfiche built-in code. The "min" property (using .prop()) is what you want to set to get the calendar to not allow the selection of days before the date you set.
If the radio buttons aren't "checked" then it will set the calendar to be the same business day as today (mind you it's business days, so if it's Saturday or Sunday it will be Monday.
It seems like you want only business days which leads me to believe you also don't want them to choose weekends. If you don't have a solution I have one in place with all this code as well that you can have. I'll post it below.
//Remove weekends from selectable options
function isCorrectDate(n) {
var t = n.getDay();
return (t!=6 && t!=0);
}
function checkDate(n) {
return[isCorrectDate(n),""];
}
function checkField(input, inst) {
if ($(input).closest('li').hasClass('myDate')) {
$(input).datepicker("option", {beforeShowDay: checkDate});
}
}
$.datepicker.setDefaults( {beforeShow: checkField} );
window.Parsley.addValidator('noweekend', {
validateString: function(value) {
return isCorrectDate(new Date(value));
},
messages: {
en: 'Not valid date.'
}
});
$('.myDate input').attr('data-parsley-noweekend','');
I can't take credit for this one. I actually got it off the answers board here but modified it a tiny bit to fit my form. It works great though and works with my code above. Please let me know if I could better elaborate on any of what I said or if you're unsure where to put in your values (Field# here, q# there, etc.)
Hopefully this answers your question as you asked it. If not let me know.