Daterangepicker - unable to select today's date

TDG picture TDG · Feb 18, 2017 · Viewed 7.1k times · Source

I used below code for date picker in my application. daterangepicker plugin used.

https://jsfiddle.net/jkenluv/z9tgdh7k/

HTML

<input class="form-control input-lg" id="tripOne" name="tripOne" />

JS:

var nowDate = new Date();
var today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);
var maxLimitDate = new Date(nowDate.getFullYear() + 1, nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);

$('input[name="tripOne"]').daterangepicker({
"autoApply": true,
"autoUpdateInput": false,
"singleDatePicker": true,
"minDate": today,
"maxDate": maxLimitDate,
"opens": "left",
"locale": {
    format: 'DD MMM YYYY'
  }
}, function (start, end) {
  $("#tripOne").val(start.format('DD MMM YYYY'));
  $('#tripOne').parent().parent().removeClass('has-error');
});

$(function() {
    $('.calendar.right').show();
});

But, i cant able to select 'Today's date' or 'already selected date'. Which is mandatory for our requirement. Please let me know how to solve this issue?

Thanks

Thanks

Answer

Maarten picture Maarten · Jun 7, 2019

Not the most beautiful solution but you can alter daterangepicker.js and remove the following line in the 'hide' method:

if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))

It will work but you can never update daterangepicker.js. It should be better to overwrite the hide method.