DateTimePicker Bootstrap 3 - How to dynamicly update enabledDates with input select choice

1.2k views Asked by At

i try to update a DateTimePicker enabledDates instance with a select choices... but Can't make my code fonctional... Here the code :

html :

<div class="row">
    <div class="col-md-12">
        <label class="control-label" for="id_concession">Concession *</label>
        <select class="form-control" id="id_concession" name="concession" required="required" title="">
            <option value="" selected="selected">---------</option>
            <option value="1">list1</option>
            <option value="2">list2</option>
        </select>
        <input type="text" class="form-control datetimepicker" id="datetimepicker1" />
    </div>
</div>

javascript :

$("#datetimepicker1").datetimepicker({
    "format": "DD-MM-YYYY"
});

$('#id_concession').change(function() {
    var val_id = $(this).val();
    if (val_id == "1") {
        var lst_date = ['15-06-2015', '16-06-2015', '17-06-2015'];
    }
    if (val_id == "2") {
        var lst_date = ['20-06-2015', '21-06-2015', '22-06-2015'];
    }

    //alert (lst_date);

    var nextElem = $(this).next('input.datetimepicker');

    if (nextElem.length > 0) {
        console.log(nextElem);
        nextElem.data("DateTimePicker").enabledDates(lst_date);
    }
});

The fiddle test area : fiddle

Thx for help lo

0

There are 0 answers