So I have a two datepickers, pretty simple stuff, to and from date...

Could you please tell me how to pass highlighted "startDate" to the date that was selected from the first datepicker.

Here is an image of a bug I'm trying to solve the date is set to current date (today), disbled date is OK, the date that should be highlighted is circled in blue:

enter image description here

And here is the source code:

    $("#mzti-start-date").datepicker({
      format: 'dd MM yyyy',
      startDate: date,
      autoclose: true
    }).on('changeDate', function(dateEvent) {
      start_date = $("#mzti-start-date").val();
      $('#mzti-finish-date').datepicker('setStartDate', start_date);
    });

    $("#mzti-finish-date").datepicker({
      format: 'dd MM yyyy',
      autoclose: true
    });

有帮助吗?

解决方案

There we go guys, solution:

    $("#mzti-start-date").datepicker({
      format: 'dd MM yyyy',
      startDate: date,
      autoclose: true
    }).on('changeDate', function(dateEvent) {
      start_date = $("#mzti-start-date").val();
      $('#mzti-finish-date').datepicker('setStartDate', start_date);
      var iso_date = new Date(start_date);
      $('#mzti-finish-date').datepicker('setDate', iso_date);
    });

There is a definitely a niftier way to do that :)

其他提示

I'm not that familiar with bootstrap datepicker (didn't actually realize there was one), but I think you just need to read the docs and follow them more closely. For instance, you're passing some options to the first datepicker, but the docs don't list a "startDate" option (though perhaps it still works). My guess is the problem is this line:

$('#mzti-finish-date').datepicker('setStartDate', start_date);

There's no "setStartDate" method, so try this instead:

$('#mzti-finish-date').datepicker('setValue', start_date);

If that doesn't work, you may need to provide more information. It's a little difficult to know what you're asking.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top