Vincent Vincent -4 years ago 131
Javascript Question

bootstrap-datepicker update value doesn't work

I'm trying to update the value of a datepicker for bootstrap when clicking a div, however it just does nothing (no errors). The datepicker itself works perfectly fine. Here's the javascript with the options:

$('#datepicker').datetimepicker({
format: 'DD-MM-YYYY',
pickTime: false,
defaultDate: moment(),
minDate: moment(),
maxDate: moment().add(10,'y'),
showClose: true,
autoclose: true,
keepOpen: false,
});


The javascript I am trying to change the date with:

$('.someDiv').click(function() {
$("#datepicker").datetimepicker('setDate', '2016-03-05');
});


And finally the HTML:

<div class='input-group date' id='datepicker'>
<input type='text' class="form-control" id="date"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>


Docs can be found under following link, however the provided method doesn't work: https://bootstrap-datepicker.readthedocs.org/en/latest/

Answer Source
  $(function () {
    $('#datepicker').datetimepicker({
  pickTime: false,
  format: 'DD-MM-YYYY', 
  pickTime: false,
  defaultDate: moment(),
  minDate: moment(),
  maxDate: moment().add(10,'y'),
  showClose: true,
  autoclose: true,
  keepOpen: false
 });

    $('.date-setter').click(function() {
        alert('jj');
      $('#datepicker').data("DateTimePicker").setDate('03-05-2016');
    });

});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download