I have a calendar field for Pay Period Begin Date (.periodBegin) and one for Pay Period End Date (.periodEnd). Employees will report their leave dates (vacation, sick...) in a table (Leave_Days_Table) containing calendar field columns for beginning leave period and ending leave period dates (.dateRange). The following code works in my Leave_Days_Table on the first row, but after clicking on the 'Add a row' link, the subsequent rows still show a calendar with all days enabled. I was hoping that the last few rows on this code snippet would restrict the dates in the next row's calendar fields, but it doesn't.
$(document).ready(function(){
function updateMinMaxDates () {
var minimum = $('.periodBegin input').val(); // get Pay Period Start Date
var maximum = $('.periodEnd input').val(); // get Pay Period End Date
var minSplit = [];
minSplit = minimum.split("/");
var newMin = (minSplit[2]+"-"+minSplit[0]+"-"+minSplit[1]);
var maxSplit = [];
maxSplit = maximum.split("/");
var newMax = (maxSplit[2]+"-"+maxSplit[0]+"-"+maxSplit[1]);
$('.dateRange input').attr('min',newMin); // disable dates before period start date
$('.dateRange input').attr('max',newMax); // disable dates after period end date
}
$('.periodBegin input').change(updateMinMaxDates);
// reset enabled date range when a row is added or removed
$('.Leave_Days_Table').on('click','.cf-table-add-row',function(){
updateMinMaxDates();
});
});