javascript - How to have datepicker set default year? - Stack Overflow

I am using bootstrap datepicker and I only show the years. When I load the page, I would like to set a

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 of defaultDate? 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
 |  Show 4 more ments

1 Answer 1

Reset to default 3

I 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'}
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745349809a4623763.html

相关推荐

  • javascript - How to have datepicker set default year? - Stack Overflow

    I am using bootstrap datepicker and I only show the years. When I load the page, I would like to set a

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信