uxsolutions / bootstrap-datepicker

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

Set dates disabled #2276

Open ViktorDimitrievski opened 6 years ago

ViktorDimitrievski commented 6 years ago

Expected behaviour

We what to use setDatesDisabled methods to disable dates from Datepicker

Actual behaviour

Nothings is happening. Datepicker is not disabling dates that we provide in array

Datepicker version used

1.6.4

Example code

 $('#datepickerSimple')
            .datepicker(options)
            .on('clearDate', this.updateDates)
            .on('changeDate', this.updateDates);

 updateDates = function () {
 this.startDate = $("#datepickerSimple [name='start']").datepicker('getDate');
this.endDate = $("#datepickerSimple [name='end']").datepicker('getDate');
this.getDisabledDates();
}

 getDisabledDates() {
        let today = new Date();
        let disableDates: Array<string> = [];
        debugger;
        for (let i = 0; i < this.startDate.getDate(); i++) {
            let date = new Date();
            date.setDate(date.getDate() + i);
            disableDates.push(date.toLocaleDateString());
        }
$('#datepickerSimple').datepicker('setDatesDisabled', disableDates);
}

<div class="input-daterange" id="datepickerSimple">
 <div class="col-md-6 col-xs-6">
      <div class="input-group">
        <input name="start" value="startValue" />
        <label>startDateT</label>
      </div>
    </div>
    <div class="col-md-6 col-xs-6">
      <div class="input-group">
        <input  name="end" value="endValue" />
        <label>endDateT</label>
      </div>
    </div>
    </div>

Jsfiddle example to reproduce the problem.

ultimagriever commented 5 years ago

The same is happening here.

ocarreterom commented 5 years ago

@ultimagriever

In v1.9.0 setDatesDisabled should be an array of date string in the same format as format option (default mm/dd/yyyy) or a Date object.