How do I disable past dates on jQuery datepicker? I looked for options but don\'t seem to find anything that indicates the ability to disable past dates.
UPDATE: Th
Try setting startDate
to the current date. For example:
$('.date-pick').datePicker({startDate:'01/01/1996'});
Give zero to mindate and it'll disabale past dates.
$( "#datepicker" ).datepicker({ minDate: 0});
Live example
read more here
Make sure you put multiple properties in the same line (since you only showed 1 line of code, you may have had the same problem I did).
Mine would set the default date, but didn't gray out old dates. This doesn't work:
$('#date_end').datepicker({ defaultDate: +31 })
$('#date_end').datepicker({ minDate: 1 })
This does both:
$('#date_end').datepicker({ defaultDate: +31, minDate: 1 })
1 and +1 work the same (or 0 and +0 in your case).
Me: Windows 7 x64, Rails 3.2.3, Ruby 1.9.3
I am using following code to format date and show 2 months in calendar...
<script>
$(function() {
var dates = $( "#from, #to" ).datepicker({
showOn: "button",
buttonImage: "imgs/calendar-month.png",
buttonImageOnly: true,
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 2,
onSelect: function( selectedDate ) {
$( ".selector" ).datepicker({ defaultDate: +7 });
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", "dateFormat", 'yy-mm-dd' );
}
});
});
</script>
The problem is I am not sure how to restrict previous dates selection.
If you are dealing with a previously bound date picker then setting
$("#datepicker").datepicker({ minDate: 0 });
will not work. That syntax is applicable only when you are creating the widget.
To set min date for a bound date picker use the following:
$("#datePicker").datepicker("option", "minDate", 0);
$("#datePicker").datePicker({startDate: new Date() });
.
This works for me