Home » Jquery » javascript – Date is not setting properly as we are selecting it from the Bootstrap-datepicker calendar

javascript – Date is not setting properly as we are selecting it from the Bootstrap-datepicker calendar

Posted by: admin February 22, 2020 Leave a comment

Questions:

I am using the Bootstrap Datepicker plugin. It’s working fine. However when I select a single-digit date from datepicker. For eg. 1/2/2020. It’s showing me the value for the previous date. PFA the screenshot.

I’m getting an error in my console:

Uncaught TypeError: Cannot read property ‘top’ of undefined

<div class="input-append date" data-date-format="dd/mm/yyyy">
  <input type="text" id="myDate" autocomplete="off" class="col-md-5 form-control inputbox-dateofbirth" data-bind="value: $parents[1].dateOfBirthValue, datepicker: $parent.dateOfBirth, onRender:$parents[1].getCalender" readonly />
  <span class="add-on"><i class="icon-calendar"></i></span>
</div>
getCalender: function() {
  var dateafterCurrentDate = new Date();
  $("#myDate").datepicker({
    endDate: dateafterCurrentDate,
    setDate: getWidget.dateOfBirthValue,
    dateFormat: 'dd/mm/yyyy',
  }).on('changeDate', function(ev) {
    //widgetLoginScope.dateOfBirth($('#myDate').val());
    $('#myDate').datepicker('hide');
  });
  console.log('date', getWidget.dateOfBirthValue());
},
How to&Answer: