Ajax validation on time of new event created!

Hello,

I want to add validation, to allow user to add 3 no. of events for one event date. for that i have added ajax call and get the count of added events. i get that count too. once i have count of event 3, light box should be closed.

Note. i am not using custom light box.

Please help me here.

my code is :

scheduler.attachEvent(“onEventSave”, function (id, e, is_new){
$.ajax({
url: ‘event_calendar.php’,
type: “POST”,
data: {rep_id : 1, sdate : action_date, eid : id},
success: function (result) {
if(parseInt(result) >= 3){
alert(‘This date is already booked. Please schedule another day!.’);
return false;
}else{
return true;// its stop to add, but, light box not closed.
}
}
});
// return true; if i use this its not wait for the ajax call response and save the event.
});

Hi,
the values you return from an ajax callback function are not returned from onEventSave handler, the callback is called after onEventSave is finished and has returned the value.
The possible solution is to cancel saving of the lightbox before the validation (this is already done in your code), and if validation succeeds - save lightbox manually.
The saving will trigger onEventSave second time, so you’ll have to set some flag in order to skip validation in this case
E.g.

[code](function(){
var validated = false;

scheduler.attachEvent("onEventSave", function (id, e, is_new){
	if(validated){
		return true;
	}else{
		$.ajax({
			url: 'event_calendar.php',
			type: "POST",
			data: {rep_id : 1, sdate : action_date, eid : id},
			success: function (result) {
				if(parseInt(result) >= 3){
					alert('This date is already booked. Please schedule another day!.');
				}else{
					validated = true;
					scheduler.save_lightbox();
				}
			}
		});
		return false;
	}
});

scheduler.attachEvent("onLightbox", function(){
	validated = false;
});

})();[/code]