How to handle if incorrect date is selected in lightbox

Hi,

How to validate if user selected incorrect/unavailable date combinations in lightbox like Feb 30, June 31 etc) ? Check the screenshot for the end_date June 31 which is not actually an invalid date. In this example, though I selected Jun30-Jun31, an event got created from June 30 -July 1st (the next available date to June 31) . Instead of creating an event I want to show error message that selected end date is not valid.

Hello @rajeswarij,

You can do it with the onEventSave event, by checking values in order to fit your requirements, and returning false and showing some alert in case if it doesn’t fit your requirement.

The code may look like follows:

scheduler.attachEvent("onEventSave",function(id,ev,is_new){
    if(+ev.start_date < +ev.end_date){
        var box = scheduler.alert({
            title:"Alert",
            type:"alert-error",
            text:"You can't do this"
        });
        return false;
    }
    return true;
})

Here is a demo(try to set an event end date before it’s start date => click the “Save” button => you will get an alert):
https://snippet.dhtmlx.com/3wsxda35

Hi,
You are checking if startDate < endDate, which means a valid event also fails.
Try this use case in your demo : startDate is May 1st 10am 2024 TO May 1st 10.30am 2024 - Though it is a valid event, it fails with your code.
My requirement is what if user selects any date and month combination which does not exists at all like Feb 31st, Feb 30, June 31 etc. These dates dont exists at all. Right now what happens is, if I select any such dates like Feb 31st as end date, it is automatically taking the next valid date as endDate (which is March 1st here). I do not want to allow event creation in such scenarios. I am not able to validate this usecase because in endDate I am seeing March 1st and not Feb 31st.