You are viewing limited content. For full access, please sign in.

Question

Question

restricting date field to grey out past dates

asked on January 26, 2018

Hi all,

i've seen a thread like this before but cant seem to find it.

i'm trying to restrict a date field from showing historical days within a month...

Thanks in advance. 

1 0

Replies

replied on January 26, 2018

Hi Mikhael,

Try this:

$(document).ready(function(){
	// Get the current date object
	var rDate = new Date("2018-01-25");
	// Set it to one month ago
	rDate.setMonth(rDate.getMonth() - 1);
	rDate = rDate.getFullYear()+"-"+(rDate.getMonth()+1)+"-"+rDate.getDate();
	// Set the minimum date attribute of the date field
	alert(rDate);
	$("#Field8").attr('min',rDate);
});		

 

1 0
replied on January 26, 2018 Show version history

https://answers.laserfiche.com/questions/121486/Restrict-Date-Picker-based-on-Time-Variables

 

you should be able to adjust the code in the answer above to work for your situation.specifically this line $('.calendarDate2 input').attr('min',minDate); its the 'min' attribute that establishes the starting point for the date picker field. See below for example code that I used to create minimum and maximum dates for Date picker fields on a form based on current date.

$(document).ready(function() {
var todaysDate = new Date();
var year = todaysDate.getFullYear();
var month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);
var day = ("0" + todaysDate.getDate()).slice(-2);
if ((month == 3 && day >= 2) || (month >= 4 && month <= 5) || (month == 6 && day == 1)) {
    var minDate = (year + "-09-01");
    var maxDate = (year + "-12-31");
    document.getElementById("term").innerHTML = "<b>This application is for funding in Fall.</b>";
    $('#q101 input').val('Fall');
} else if ((month == 6 && day >= 2) || (month >= 7 && month <= 10) || (month == 11 && day == 1)) {
    var nextYear = (todaysDate.getFullYear() + 1);
    var minDate = (nextYear + "-01-01");
    var maxDate = (nextYear + "-05-11");
    document.getElementById("term").innerHTML = "<b>This application is for funding in Spring.</b>";
    $('#q101 input').val('Spring');
} else if ((month == 11 && day >= 2) || month == 12) {
    var nextYear = (todaysDate.getFullYear() + 1);
    var minDate = (nextYear + "-05-12");
    var maxDate = (nextYear + "-08-31");
    document.getElementById("term").innerHTML = "<b>This application is for funding in Summer.</b>";
    $('#q101 input').val('Summer');
} else if (month <= 2 || (month == 3 && day == 1)) {
    var minDate = (year + "-05-12");
    var maxDate = (year + "-08-31");
    document.getElementById("term").innerHTML = "<b>This application is for funding in Summer.</b>";
    $('#q101 input').val('Summer');
}
$('.startDate input').attr('min', minDate);
$('.startDate input').attr('max', maxDate);
});
});

 

0 0
replied on February 1, 2018

Thanks guys, i'll give these a go.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.