I have been able to get the Datepicker to only show the Sundays on a calendar. This is from this answers post: https://answers.laserfiche.com/questions/127082/Forms-102-Calendar-Restricted-Date-JavaScript-Needed
We would like to expand on this and see if we could get the Datepicker to show every other Sunday starting from a particular date. This will enable us to pick the starting of a pay period on the form.
The current java script that I am using from the aforementioned post:
$(document).ready(function(){
var startDate = new Date('05-03-2020');
function isCorrectDate(n, target) {
var t = n.getDay();
return (t==target);
}
function checkField(input, inst) {
if ($(input).closest('li').hasClass('startSun')) {
$(input).datepicker("option", {minDate: startDate, beforeShowDay: function(n) {return [isCorrectDate(n, 0),""]}});
}
if ($(input).closest('li').hasClass('endingSat')) {
$(input).datepicker("option", {beforeShowDay: function(n) {return [isCorrectDate(n, 6),""]}});
}
}
$.datepicker.setDefaults( {beforeShow: checkField} );
window.Parsley.addValidator('ending', {
validateString: function(value, target) {
return isCorrectDate(new Date(value), parseInt(target));
},
messages: {
en: 'Not valid date.'
}
});
$('.startSun input').attr('data-parsley-ending','0');
$('.endingSat input').attr('data-parsley-ending','6');
});
I have found another java script from another site that does what we want, but I have been unable to convert it to work within Forms. The code that I found is here:
// Enable Pay Periods only
$("#payPeriodPicker").datepicker({
dateFormat: 'mm-dd-yy',
beforeShowDay: payPeriodsOnly
});
//Logic to enable every sunday, how to do every other sunday?
function payPeriodsOnly(date) {
var day = date.getDay();
var oneDay = 24 * 60 * 60 * 1000; //milliseconds in one day
var startingDate = new Date(2020, 5, 3);
var diffDays = (Math.abs(startingDate.getTime() - date.getTime()) / oneDay);
return [((day == 0) && (Math.ceil(diffDays) % 14 == 0)), '']; //sunday and every other weeks
}
Does anyone have any help in getting either script to work to every other Sunday?