I have a start date and end date for me to choose the date. I am using jQuery datepicker library.
This is how my function looks like for now:
$(function() {
$(".txtEndDate").datepicker({
changeMonth: true,
changeYear: true,
showOn: 'button',
buttonImage: '../../../images/calendar.png',
buttonImageOnly: true,
title:'Click to open calendar',
alt:'Click to open calendar'
});
});
$(function() {
$(".txtStartDate").datepicker({
changeMonth: true,
changeYear: true,
showOn: 'button',
buttonImage: '../../../images/calendar.png',
buttonImageOnly: true,
title:'Click to open calendar',
alt:'Click to open calendar',
onSelect: function() {
var start = $(this).datepicker("getDate");
start.setDate(start.getDate() + 7);
$(".txtEndDate").datepicker("setDate", start);
}
});
});
It works but I want to make it when users are not allowed to choose a date before today because it doesn't make sense anyway.For example,choosing 2018-01-01
is not supposed to be valid. You get the idea.
Found a documentation that suggests using minDate
to solve this.It says:
//initialize the datepicker
$( ".selector" ).datepicker({
minDate: new Date(2007, 1 - 1, 1)
});
//get or set mindate option
// Getter
var minDate = $( ".selector" ).datepicker( "option", "minDate" );
// Setter
$( ".selector" ).datepicker( "option", "minDate", new Date(2007, 1 - 1, 1) );
Seeing as I am confused on what the fields represent, is there a way I could prevent people from selecting any dates before today?
I tried this solution: jQuery Date Picker - disable past dates
But it doesn't disable it and still allows me to choose.