Disable selected dates using Editor Datepicker

Disable selected dates using Editor Datepicker

Workflow Automation ExpertWorkflow 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

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0

    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

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    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

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0

    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.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    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, a Date object that should be checked. Return true if that date should be disabled in the picker.

    Regards,
    Allan

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0
    edited August 13

    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

    var testdate = new Date("28-aug-2024")
            ...
            disableDays: function(testdate){if (testdate.getDay()=== 3){return true}}
    

    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

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    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 the disableDays function, it should make that date unselectable.

    Here is a little example: https://live.datatables.net/gotoxese/1/edit that will disable Wednesdays.

    Allan

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0

    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.

Sign In or Register to comment.