3

I have a date and time picker using pickadate.js, im trying to do dynamic time disabling, here is what i have

var allUserSchedules = [
    ["26 December, 2017", {from: [00,00], to: [01,00]}],
    ["29 December, 2017", {from: [16,00], to: [19,00]}]
];

var timePickerInput = $('#bookingTime').pickatime();

$('#bookingDate').on('change', function() {
    var timePicker = timePickerInput.pickatime('picker');
    var timeSlotTaken = [];
    var generateDate;
    generateDate = $('#bookingDate').val();
    for (i = 0; i < allUserSchedules.length; i++) { 
        if (generateDate == allUserSchedules[i][0]) {
            timeSlotTaken.push(allUserSchedules[i][1]);
        }
    }

    console.log(timeSlotTaken);
    $('#bookingTime').show();
    timePicker.set('disable', timeSlotTaken);
    timePicker.set('interval', 60);
});

The flow is, user picks a date -> JS checks if there are same dates between input date and dates inside arrays and return those same dates -> from those same dates get the time slot taken

It is working as expected when i FIRST select a date, however, the next times i do it, the time slots taken from the first selected date is also there, it does not refresh. Anyone has experienced this before or has a solution to this issue ?

This is the only thread i could find that seems to have same issue as me with no solution, although in that thread the issue is with dates not times.

yomamen
  • 31
  • 1
  • 4

0 Answers0