Reputation: 3893
I have a scenario with jQuery datepicker where the user is editing an event that occurs in September, but the current month is June.
The user unselects all dates and the datepicker but the datepicker jumps back to June.
The required behaviour is that the datepicker stays in September, with no dates selected.
Is there a default parameter to handle this, without writing a custom handler in the onSelect hook?
Upvotes: 0
Views: 3135
Reputation: 3997
There is no datepicker parameter to set a default month, you have to set it by default date option. Helpful link here
defaultDate
Type: Date or Number or String
Default: null
Set the date to highlight on first opening if the field is blank. Specify either an actual date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.
Multiple types supported:
Code examples:
Initialize the datepicker with the defaultDate option specified:
$( ".selector" ).datepicker({
defaultDate: +7
});
OR
$( ".selector" ).datepicker({ defaultDate: new Date() });
OR
$(function() {
$('.selector').datepicker( {
// ...
});
var default_date = new Date(2023, 10, 1);
$(".selector").datepicker("setDate", default_date);
});
Upvotes: 1