How to validate Start, End date and cu in Scheduler lightbox

Hi,

I am trying validation for Start Date, End Date and Current date.
I am facing 2 issues :-

  1. I am trying to validate Start and End date in the Scheduler lightbox.
    Following code I am using :-
    if(dhx.i18n.fullDateFormatStr(data.start_date) < dhx.i18n.fullDateFormatStr(data.end_date)){
    alert(“Start Date should be less than End date”);
    }

But here I am facing some problem. When I select Start Date greater than End Date scheduler automatecally assigns Start Date value to End Date.

  1. Another issue is I am also validating Start date with current date.
    Following code I am using :-

if(dhx.i18n.fullDateFormatStr(data.start_date) < dhx.i18n.fullDateFormatStr(new Date())){
alert(“Start Date with time should not be less than current date with time.”);
}

Its works fine for Same month but do not work for different months.

PFA demo.

Please help to resolve this issue.

Thanks in advance for help.

Regards,
Vishal Kadam.
cal.zip (244 KB)

Hello,

Yes, if you return true for the onEventSave event. If that’s not desired behavior then show alert and return false.

Actually it’s a bad idea to compare dates using string. You should work directly with the date objects, for example:

[code]scheduler.attachEvent(“onEventSave”,function(id,data,is_new_event){
var Comments = scheduler.formSection(‘Comments’).getValue(); // what for?
var current_date = new Date();

if(data.start_date > data.end_date){
	alert("Start Date should be less than End date");
	return false; // event won't be saved, user can fix start date
}
if(data.start_date < current_date){
	alert("Start Date with time should not be less than current date with time.");
	return false;
}

retrun true; // default action, event will be saved

}); [/code]
Kind regards,
Ilya