Disable selected dates using Editor Datepicker
Disable selected dates using Editor Datepicker
Workflow Automation Expert
Posts: 14Questions: 4Answers: 0
I note you can disable and array of week days on the Editor datepicker using disableDays.
Any way of disabling select dates i.e ['2024-08-14','2024-08-20']?
This question has accepted answers - jump to:
Answers
Noted from other forum post that the above question I asked is not possible.
Have proceeded to try install Editor plugin Bootstrap Datepicker as this has the functionality I require https://editor.datatables.net/plug-ins/field-type/editor.datetimepicker-2
However, I get the following error in initialisation....
Uncaught runtime error: Script error. at https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js:0, column 0 undefined error-handling.ts:178:12
Hi,
Yes, as you say, at the moment that is not something that is possible with the DataTables DateTime library. That is something I can look at adding.
I don't know why the Bootstrap DateTime Picker library is giving an error I'm afraid. The error seems to suggest it is happening on line 0, which is a bit odd. P resume
error-handling.ts
is one of your files capturing all errors?Allan
Thank you. It would be greatly appreciated if you can add the disabling of selected dates.
I have resolved a workaround to perform a function onChange, to display an alert to the user, when a date selected is unavailable.
I was just starting to look at how I might implement this feature and while looking at the code it appears that I've actually done it already! Apologies for having forgotten that.
The
disableDays
option can be given as a function. It is passed a single parameter, aDate
object that should be checked. Returntrue
if that date should be disabled in the picker.Regards,
Allan
Hi Allan,
Apologies for the delayed response, been away from office.
Thank you for looking into this, very much appreciated.
I have tried to understand your suggestion above i.e
However, the function seems to still iterate through every date of the viewable calendar, not just the specific date provided.
Have I understood you correctly?
Regards,
Arnold
Hi Arnold,
When the calendar is displayed for a month, the function will be called for every date in that month. You need to then check if a date should be disabled or not. If you return
true
from thedisableDays
function, it should make that date unselectable.Here is a little example: https://live.datatables.net/gotoxese/1/edit that will disable Wednesdays.
Allan
OK, I'm now on the same page as you Allen,
Therefore, to block out 28-Aug-2024 the code will be as follows...
{disableDays: function(calenderdate) {
if (calendardate.setHours(0,0,0,0) === new Date('28-aug-2024').getTime()){
return true;
} else {
return false;
}
}
});
Thank you, can work with this.