Reputation: 531
I implemented bootstrap datepicker.I want to set the default date to 30 days from today's date.I also want to disable dates after 3 months.Is there any way to achieve this.
For example, today date is 30 oct.On showing datepicker instead of showing 30 oct it should show 31 Nov and I want to disable dates from Jan 2013.
Thanks
Upvotes: 0
Views: 1972
Reputation: 47667
Try this - DEMO
The default date is 30 days from now and the end date is 90 days from now
var plus30days = new Date(),
plus90days = new Date();
plus30days.setDate( plus30days.getDate() + 30 );
plus90days.setDate( plus90days.getDate() + 90 );
$( "#datepicker" )
.datepicker( "setValue", plus30days )
.on( "changeDate", function(ev) {
if ( ev.date.valueOf() > plus90days.valueOf() ) {
alert( "Hey-hey-hey! Wait a minute!" );
$( "#datepicker" ).datepicker( "setValue", plus30days );
}
$( "#datepicker" ).datepicker( "hide" );
});
Upvotes: 3