How does Datepicker only select future dates and disable past date in JQuery and CSS?
What class should be used for datepicker to use future dates only?
<form:input path="FutureDato" type="date" class="datepicker maxDateToday hasDatepicker" />
Note . The code was written by someone else. The above code does not allow you to enter a date in the future, or you can tell that to disable future dates when you click on the calendar. I want the code to disable past dates and only show dates for future years. I can't figure out how these classes work here (datepicker, maxDateToday); couldn't find it in CSS. I don't know what the JQuery is running on; if yes then i can't find the same. If such classes are predefined, can you help me find the class?
To make any past dates unavailable, you first need to find the datepicker instance and set the parameter minDate
to 0.
$('element').datepicker({
minDate : 0
});
Better solution to disable past dates and select only future dates:
Try this, it works in my case:
$( ".selector" ).datepicker({
startDate: new Date()
});
Use datepicker minDate () method, you can find api details http://api.jqueryui.com/datepicker/
$( ".selector" ).datepicker({
minDate: new Date()
});
for this you first need to import the jQuery-UI script https://code.jquery.com/ui/
I hope this works.