Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 555
Danish Adeel Avatar asked Dec 01 '25 09:12

Danish Adeel


1 Answers

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">
like image 170
Gvidas Avatar answered Dec 04 '25 00:12

Gvidas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!