Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable specific times in a specific day #789

Open
aM0N12 opened this issue Mar 15, 2022 · 2 comments
Open

Disable specific times in a specific day #789

aM0N12 opened this issue Mar 15, 2022 · 2 comments

Comments

@aM0N12
Copy link

aM0N12 commented Mar 15, 2022

Hello,

I want to disable specific times in a specific day (not the entire day), how can i achieve it ?

Best regards

@lukejames1111
Copy link

I desperately want this too, but I can't find any way 🙁 I can only disable entire days, which I don't want to do.

@lukejames1111
Copy link

Ok, I've actually figured it out myself 😄

First we get the dates and times in a multidimensional array and JSON encode the array (I'm using PHP, but the logic is still the same no matter what language you use).

$times[]=[
    '2022-04-28'=>[
        'hour' => 10,
        'minute' => 30
    ]
];
$times[]=[
    '2022-04-28'=>[
        'hour' => 11,
        'minute' => 15
    ]
];
$times[]=[
    '2022-04-29'=>[
        'hour' => 13,
        'minute' => 30
    ]
];

$dates=json_encode($times);

And then in our function we loop through the array and do a simple if statement which says if the date is in the array then to apply a class to that which disables the date 😄

jQuery('#datetimepicker').datetimepicker({
    lang:'en',
    format:'Y-m-d H:i',
    formatDate:'Y-m-d',
    step:15,
    onGenerate: function(ct, $i){
        var date=moment(ct).format('Y-MM-D');
        var datesArray=<?echo $dates;?>;

        $.each(datesArray, function(i, dates){
            if(date in dates){
                var times=dates[date];
                $.each(times, function(index, time){
                    var hour=times['hour'];
                    var minute=times['minute'];
                    var $object=$('[data-hour="' + hour + '"][data-minute="' + minute + '"]');
                    $object.addClass('xdsoft_disabled');
                });
            }
        });
    }
});

You just have to note that the date format must be the same within the function to whatever it is you have stored in your array. Also, my step is set to 15, which only disables that exact time. You'd need to change this to whatever format you use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants