简体   繁体   中英

What is the proper way to use the Months view in Bootstrap Datepicker?

I'm trying to use the month view on Bootstrap Datepicker

I have the following HTML:

<div class="form-group col-12">
  <input id="portalDownloadMonth" type="text" readonly class="form-control pl-3" data-date-format="mm-yyyy" data-date-viewmode="months" placeholder="Mes" required>
</div>

And the following JavaScript

$('#portalDownloadMonth').datepicker({
  format: "mm-yyyy",
  viewMode: "months", 
  minViewMode: "months",
});

But this is not working at all, the input shows the day view

在此处输入图片说明

Can someone tell me what I missing?

Using the bootstrap-datepicker from the tag you provided on the question, you need to use:

format: "M yyyy",

Example snippet:

 $('.datepicker').datepicker({ format: "M yyyy", viewMode: "months", minViewMode: "months" });
 <link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet" /> <link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.1/css/bootstrap-datepicker3.css" rel="stylesheet" /> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.1/js/bootstrap-datepicker.js"></script> <input type="text" class="datepicker" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM