Error after scheduler.eventDelete

Dear,

After having created an event, I got a test to check if this new event his for an user who already got one… in order to avoid multiple events for a same user.
If an event already exists for this user, I delete the new one.
All is ok with the deletion but I got a javascript error when the mouse moves over the scheduler after the new event is deleted.
“date_start” has null value or is not an object"

below my code


scheduler.attachEvent(“onEventCreated”, function(event_id,event_object){
var evs = scheduler.getEvents(new Date(2000,1,1),new Date(2050,1,1));
var ChaineId=’’;
var IdEventPresid=’’;
for (var i=0; i<evs.length; i++)
{
ChaineId=ChaineId+evs[i].details+’$’;
if (evs[i].details==IdPresid)
{
IdEventPresid=evs[i].id;
}
}
if (ChaineId.indexOf(IdPresid)==-1) // my test (event_id must not be in ChaineId)
{
var ev=this._events[event_id];
ev.details=“NewId”;
}
else
{
alert('just one event );
scheduler.deleteEvent(event_id);
}
}); **********************

thanks for your help

component doesn’t expect that event will be deleted in the onEventCreated handler, which is cause the issue.

Instead of it, you can use onBeforeDrag event which occurs when user tries to create event by d-n-d ( or change size|position of an existing event ) - returning false from the handler will block creation of new event.

Next may be used with your current solution, but it based on inner logic and may not work correctly ( never was tested )

else { alert('just one event ); scheduler._drag_id = this._drag_mode = null; scheduler.deleteEvent(event_id); }

Dear Stanislav,

Thanks for your quick answer…

I’ve tried to put the code in the onEventCreated event has seen in this topic
viewtopic.php?f=6&t=3449&p=10300&hilit=deleteEvent#p10300

but maybe I didn’t understand the aim of this topic.

So I will try your solution with OnBeforeDrag…

Thanks

I've tried to put the code in the onEventCreated event has seen in this topic

Normally you can change properties of event - alter start and end time for example, but it not purposed for event deleting.

I solved my problem…

In fact, the problem was that in the onCreatedEvent.
I thought that this event was called after event creation, but it’s called after event initialisation (date_start, id, text…) but the focus is still on the event until the end of the function, so no date_end.
As I was alerting the user with a javascript alert, the scheduler was missing the focus.

I can not use the onBeforeDrag because my user must be able to change his other event.

So I keep my test in onCreatedEvent, initialize a global variable which I test after in the onEventAdded

below my code, if this can help others


var IdEventToDelete=‘0’;

scheduler.attachEvent(“onEventCreated”, function(event_id,event_object){
var evs = scheduler.getEvents(new Date(2000,1,1),new Date(2050,1,1)); /browse all events/
var AllUserId=’’;
for (var i=0; i<evs.length; i++) /* I retrieve in a string the user_id of each event (stored in ‘details’ in XML and compare to current user_id which is stored in UserId */
{
AllIdUser=AllIdUser+evs[i].details+’$’; }
if (AllUserId.indexOf(UserId)!=-1) // the test
{IdEvenementSupprimer=event_id;}
});

scheduler.attachEvent(“onEventAdded”, function(event_id,event_object){DeleteEvenement();});

/… end of initialization/
}

function DeleteEvent()
{
if (IdEventToDelete!=‘0’)
{
scheduler.deleteEvent(IdEventToDelete);
alert(‘Just one event per user’);
IdEventToDelete=‘0’;
}
}


:arrow_right: maybe the post subject can be replace by “limiting to one event per user”

Thanks to all… scheduler as all your components is great… good jod :sunglasses: