I am using bootstrap datepicker and I only show the years. When I load the page, I would like to set a default year, tried the following but the current year (2018) is hightlited instead.
$('#sandbox-container div').datepicker({
format: "yyyy",
viewMode: "years",
minViewMode: "years",
updateViewDate: false,
changeYear: true,
defaultDate: '2014'
});
Thing is this is an Edit page, so the year is ing from the db, therefore I need to be able to set a default year as per the value I am getting from the db.
I am using bootstrap datepicker and I only show the years. When I load the page, I would like to set a default year, tried the following but the current year (2018) is hightlited instead.
$('#sandbox-container div').datepicker({
format: "yyyy",
viewMode: "years",
minViewMode: "years",
updateViewDate: false,
changeYear: true,
defaultDate: '2014'
});
Thing is this is an Edit page, so the year is ing from the db, therefore I need to be able to set a default year as per the value I am getting from the db.
Share Improve this question asked Jun 3, 2018 at 2:32 rob.mrob.m 10.6k21 gold badges88 silver badges175 bronze badges 9-
1
Have you tried
startDate
instead ofdefaultDate
? bootstrap-datepicker.readthedocs.io/en/latest/… – mr rogers Commented Jun 3, 2018 at 2:46 -
Or even
defaultViewDate
bootstrap-datepicker.readthedocs.io/en/latest/… – Get Off My Lawn Commented Jun 3, 2018 at 2:47 -
@mrrogers as per the code above, if I do
startDate: '2014'
I still get current year, not sure what I'm doing wrong – rob.m Commented Jun 3, 2018 at 2:47 -
@GetOffMyLawn same thing, if I use the code in the question and do
defaultViewDate: '2014'
I still get current year highlighted – rob.m Commented Jun 3, 2018 at 2:48 -
1
Then that must be patible with
format
– Get Off My Lawn Commented Jun 3, 2018 at 2:52
1 Answer
Reset to default 3I had to change updateViewDate: false
into updateViewDate: true,
so:
$('#sandbox-container div').datepicker({
format: "yyyy",
viewMode: "years",
minViewMode: "years",
updateViewDate: true,
changeYear: true,
defaultViewDate: {year: '2014'}
});