Add a disabledDateTimes attribute
Currently, we have allowedTimes and disabledDates. However, if I want to disable a certain time on a given date, I find no way of doing this? I presume this could be done as an onGenerate function somehow, but it feels a bit hacky and like something that should be possible straight away. I might fork and do a PR for this if I have time.
For now, I have solved this with
onGenerate: function(ct, $i) {
var date = ct.dateFormat('Y-m-d');
var dates = <?php json_encode($resource->dates['taken']['times']) ?>
if (date in dates) {
var times = dates[date];
$.each(times, function(index, time) {
var hour = time['hour'];
var minute = time['minute'];
var $object = $('[data-hour="' + hour + '"][data-minute="' + minute + '"]');
$object.addClass('xdsoft_disabled');
});
}
}
Here, I pass through "dates", which is a json-encoded PHP array, formatted as follows:
<?php
// $times = $dates['taken']['times']
// Using the standard formatting codes
$times['Y-m-d'] = [
'hour' => 'H',
'minute' => 'i',
]
// Example – this will make the dateTime 2015-06-22 14:45 greyed out in the calendar
$times = [
'2015-06-22' => [
'hour' => 14,
'minute' => 45
]
]
So given a PHP DateTime object (or in my case, Carbon, which extends DateTime), we can simply use the formatting option to get the date formatted, as well as hour and minute. The reason I chose the format I did was because that's how it's stored in MySQL datetime, which is used in my backend. You could of course change this to use whatever formatting you like, simply modify var date = ct.dateFormat('Y-m-d'); in the onGenerate script to your liking.
I have already made a pull request with the properties to disable "minTime" and "maxTime".
https://github.com/xdan/datetimepicker/pull/288
@Znow yep, but it doesn't allow for multiple datetimes being disabled, it merely does interval breaks (although that is very useful too)
@phroggyy - Yep exactly, and I actually also have a need to disable multiple time ranges for a specific date. Do you think we could extend my added functionality?
@Znow I'll have a look at it this weekend!
@phroggyy - Nice.. was thinking of doing a new propery "disabledMinMaxTimes", which took an array of arrays of objects.
So, an array of 2 or more objects which would contain ie.:
First object: 25-06-2015 12:00 - 14:00 Second object: 25-06-2015 16:00 - 18:00 and so on...
And still leaving the "disabledMinTime, disabledMaxTime" be, for use with single times on a specific date.
@Znow after a bit of thinking, and realising I have quite demanding needs, I realised something that would be even cooler; RegEx pattern matching of excluded days. So you would supply an array of patterns, and all dates and times matching that would be disabled. Probably, you'd want to check the times whenever a date is clicked, and start matching date + time, and matching date on month change. That way, your example of matching objects could, if desired, be reduced to one RegEx pattern, alternatively two separate patterns.
@phroggyy Yeah, you could do that. I have the needs, of when selecting a date, the specified time ranges should be disabled.
Did this ever get implemented? I have a need for adding a way of disabling specific times on a specific date.