Reputation: 1923
In rails 3.2.13 project, I am using bootstrap datepicker plugin. Right now calender is displaying the current date by disabling the previous dates. Now I need to restrict the calender to select the current date + next 30 days only.
I am using below code to disable the previous date,
function currentDatePicker(id){
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
$('#' + id).datepicker({
format: "yyyy-mm-dd",
onRender: function(date) {
return date.valueOf() < now.valueOf() ? 'disabled' : '';
}
});
}
Upvotes: 3
Views: 16553
Reputation: 141
In Bootstrap datepicker Set Current date Use: startDate: new Date()
it desible previous date.
Set next 30 days use: endDate: '+30d'
It shows only 30 days from the current date
here the example code:
$('#datepicker').datepicker({ startDate: new Date(), // controll start date like startDate: '-2m' m: means Month endDate: '+30d' });
Upvotes: 5
Reputation: 1
Try this its working demo: http://jsfiddle.net/1wsf97pt/
$(function () {
$("#Id").datepicker({
minDate: new Date,
onSelect: function (dateText, inst) {
try {
$.datepicker.parseDate('mm/dd/yy', dateText);
} catch (e) {
alert(e);
};
}
});
});
Upvotes: -1
Reputation: 3559
Try this:
$('#datepicker').datepicker({
startDate: 0,
endDate: '+30d'
});
Upvotes: 1
Reputation: 57095
Try maxDate
$('#' + id).datepicker({ maxDate: "+30d" });
or
$('#' + id).datepicker( "option", "maxDate", "+30d" );
$('#' + id).datepicker({
maxDate: "+30d",
minDate:0
});
Upvotes: 4