Rui, we seem to have more restrictions needed on calendars that the out-of-the-box Forms solutions cannot offer. You've now been able to help me twice with these restrictions, so if you could do it again, I'd greatly appreciate it!
This time, the restrictions are on two different forms, and therefore require different JS requirements. The first is the Form we'd been discussing above (limiting calendar selection to only to Saturdays or Fridays). In addition to the coding you provided me (see below), they would now like to limit the calendar to only the current month, or the previous month for selection. Can we achieve this? Here is the code, as it currently stands, on that Form.
$(document).ready(function(){
$('td[data-title="Total:"] input[type="text"]').attr('readonly', 'True');
$('td[data-title="Total"] input[type="text"]').attr('readonly', 'True');
function isCorrectDate(n, target) {
var t = n.getDay();
return (t==target);
}
function checkField(input, inst) {
if ($(input).closest('li').hasClass('endingFri')) {
$(input).datepicker("option", {beforeShowDay: function(n) {return [isCorrectDate(n, 5),""]}});
}
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.'
}
});
$('.endingFri input').attr('data-parsley-ending','5');
$('.endingSat input').attr('data-parsley-ending','6');
})
The second Form's calendar restriction does not have the same rules applied to it as above. However, the goal is to have it only show the 1st and the 16th as valid dates to select in each month. Everything else should be greyed out. Is it possible to achieve this? Thank you!