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);
}
}); **********************
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.
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;}
});
function DeleteEvent()
{
if (IdEventToDelete!=‘0’)
{
scheduler.deleteEvent(IdEventToDelete);
alert(‘Just one event per user’);
IdEventToDelete=‘0’;
}
}
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
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan