Search code examples
jquerydatepickerbootstrap-datepicker

Overwrite options for bootstrap datepicker


I have define a generic options for all datepickers of my site in a js file, now I am trying to update/overwrite specific field through id, but I am unable to achieve it.

 **HTML**
 <input id="mydate" class="datepick" type="text">

 **JS**
 $('.datepick').datepicker({
     autoclose: true,
     todayHighlight: true,
     /* startDate: '+1m'  This option will work here*/
 });

  $('#mydate').datepicker({
     startDate: '+1m' /* But it doesnt work here*/
 });

Here is a fiddle http://jsfiddle.net/LT7qE/90/


Solution

  • You need to use setStartDate to set start date after datepicker was initialized

    Here's jsFiddle

     $('.datepick').datepicker({
         autoclose: true,
         todayHighlight: true,
         /* startDate: '+1m'  This option will work here*/
     });
     
      $('#mydate').datepicker('setStartDate','+1m');
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/css/datepicker.css" rel="stylesheet"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/js/bootstrap-datepicker.min.js"></script>
    <input id="mydate" class="datepick" type="text">