Creating multiple entries instead of recurring events

Hi,

A while ago, I asked about creating multiple entries of events in the database instead of using a recurring event field.
I was told to use the following code:

if(new_event_id!='' && event_object.rec_type){ var eventText = event_object.text; var spaceID = event_object.space_id; var extraID = event_object.extra_id; var details = event_object.details; var eventType = event_object.event_type; var repeatArray = scheduler.getRecDates(new_event_id); var new_id = new_event_id; //added for (var i = 0; i < repeatArray.length; i++){ var start_date = repeatArray[i]['start_date']; var end_date = repeatArray[i]['end_date']; scheduler.addEvent({ id:new_id, //added start_date: start_date, end_date: end_date, text:eventText, event_pid:'0', rec_type:'', details:details, event_length:'0', approved:'1', space_id:spaceID, extra_id:extraID, event_type:eventType }); new_id = scheduler.uid(); //added } }

This is in the onEventIdChange function. It works fine when I add an event.
However, this is only run when an event is first created, therefore, when I edit an existing event and set it to be recurring, it doesn’t add the additional instances to the database.
In fact, the Save button does nothing. It doesn’t even save the current info.

So here are my 2 questions:

  1. When editing an existing event and pressing ‘Save’, it doesn’t work if the event has been set to be recurring (there’s no JS error). Why is this and how can I fix it?
  2. Where is the best place to put the above code so that it gets run and the multiple events added regardless of whether a new event or existing event is being made recurring?

You can try out the system here - shul.co.uk/diary/admin/calendar.php

Thanks!

(1)
onEventIdChange is triggered only after adding new record to the database. When you are saving already existing event, onEventIdChange handler is not triggered at all. You can attach extra code to onEventChanged, which is called after each update, and from it check is this is a case of saving event as recurring and if necessary trigger the same logic as described above

(2)
You can move the code in standalone function and call it from both onEventChanged and onEventIdChange events.

onEventChanged is exactly what I needed, thanks!

But that still doesn’t fix my first problem.
That was when I have an existing event selected, and I choose to make it recurring, the ‘Save’ button does nothing (it doesn’t even save the event normally). As that doesn’t happen, onEventChanged doesn’t run, and therefore I can’t see if your solution worked.
No error appears when pressing ‘Save’. Literally nothing happens.

Any idea why this could be?

Check a code of event handlers, be sure that all of them have “return true;” at the end.
For some event handlers not returning anything from event or returning false will block a related operation.

Is there any function that only gets run if the recurring events is enabled?
Because the edit event works fine when I haven’t selected a recurring event.

In case of recurring event the inner processing is a more complicated, but as for event handlers - they are the same for the normal and recurring event.

Do you have some kind of demo, where problem can be checked.

Yep, you can see it at shul.co.uk/diary/admin/calendar.php

You have at least one typo in js code

var repeatArray = scheduler.getRecDates(new_event_id); 

here the new_event_id need to be replaced with event_object.id

Thanks for that.
But regardless of that, even if I change the onEventChanged function to this:

scheduler.attachEvent(“onEventChanged”, function(id, event){
return true;
});

the saving events still doesn’t work if I have set the event to be a repeated one.
And there’s no error in the JS console.

Any update on why this is?

During data saving event collision occurs, and code of onEventCollision handler blocks the data saving.

Thanks so much!

Turns out that function was telling me that event X is colliding with event X and therefore can’t be saved.

Fixed now :slight_smile: