uxsolutions / bootstrap-datepicker

A datepicker for twitter bootstrap (@twbs)
Apache License 2.0
12.67k stars 6.07k forks source link

setting startDate on a daterange picker fails #967

Open felixwahner opened 10 years ago

felixwahner commented 10 years ago

I'm currently trying to update this datepicker:

    <div class="input-daterange input-group" id="datepicker">
        <input  type="text" class="form-control datepicker" name="start" />
        <span class="input-group-addon">bis</span>
        <input type="text" class="form-control datepicker" name="end" />
    </div>  

...which is initialized like this:

    var dp = $('.input-daterange').datepicker({
        format: "MM yyyy",
        startDate: moment().subtract('months',1).format('MM-YYYY'),
        endDate: moment().format('MM-YYYY'),
        minViewMode: 1,
        language: "de",
        autoclose: true
    });

With this code...

    $('.input-daterange').datepicker( 'setStartDate', moment(startDate).date() );

...where startDate is a dynamic Date which is updated when selecting some options in a dropdown. Sadly this doesn't work as expected.

When I'm doing a "console.log(data[option])" in the $.fn.datepicker at line 1379 checking if the method setStartDate exists it returns undefined. Am I mistaking or is this a bug?

dre-hh commented 9 years ago

I can confirm this. Setting startDate or endDate fails if it's using custom format. E.g below code has no effect on start or end_date

$('.datepicker').datepicker({
   startDate: '20141015',
   endDate: '20141030',
   language: "de",
   autoclose: true,
  format: "yyyymmdd"

});

Phillita commented 9 years ago

I can also confirm this. I tried to create a Year picker but was unable to limit the date range. I was able to get it to work by formatting my dates differently though.

Working example:

$('#year').datepicker({
    startDate: "-35y",
    endDate: "-1d",
    minViewMode: 2,
    format: 'yyyy'
});

Failing Example:

$('#year').datepicker({
    startDate: "01/01/1990",
    endDate: "01/01/2015",
    minViewMode: 2,
    format: 'yyyy'
});
philwig commented 8 years ago

Just keeping this alive as exactly the same problem. When Donald Trump conquers us all this will not be an issue; in the mean time, it's not great.