I am trying to have a date Range select using the UI date picker.
in the from/to field people should not be able to view or select dates previous to the present day.
This is my code:
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
Can some one tell me how to disable dates previous the to the present date.
Use the "minDate" option to restrict the earliest allowed date. The value "0" means today (0 days from today):
Docs here: http://api.jqueryui.com/datepicker/#option-minDate
This is easy way to do this
also we can disable future days
Live Demo ,try this,
You must create a new date object and set it as
minDate
when you initialize the datepickersEdit - from your comment now it works as expected http://jsfiddle.net/nicolapeluchetti/dAyzq/1/
Declare dateToday variable and use Date() function to set it.. then use that variable to assign to minDate which is parameter of datepicker.
That's it... Above answer was really helpful... keep it up guys..
just replace your code:
old code:
new code: