Problems with refreshing and double items (dynamic loading)

Hello, I’ve been using v2.3 of the dhtmlxScheduler, but I have 2 problems.

1st problem: When I am in the day view, I see every item once. But when I open the week view, it loads (dynamically) the items from that week. But the items of the day selected at first are still in there, so they show up double.

2nd problem: When I create an item, somehow all items “lock”. I can drag and drop them, but the new date isn’t saved. When I press F5 to refresh, I can change every item. This only occurs when I place a new item in the scheduler.

I use this code to refresh after placement of an item:

scheduler.attachEvent("onEventAdded", function(){ window.setTimeout(function(){ scheduler.clearAll(); scheduler.load(loadUrl); }, 1); });

Other settings I use:

scheduler.config.show_loading = true;
scheduler.config.details_on_create = true;
scheduler.config.details_on_dblclick = true;
scheduler.config.xml_date="%Y-%m-%d %H:%i";
scheduler.config.prevent_cache = true;
scheduler.config.time_step = 15;
scheduler.config.scroll_hour = 7;
scheduler.config.icons_select = ["icon_details", "icon_delete", "icon_custom"];
scheduler.config.multi_day = true;
scheduler.config.full_day = true;
scheduler.init('scheduler_here', null, curTab);
scheduler.load(loadUrl, "json");

so they show up double.
Be sure that event’s in xml (json) have valid and constant IDs ( same events must have the same id, for every data loading operation )

2nd problem:
If you are using dataprocessor for data saving, most probably insert operation returns invalid response, which block further data operations.

In the JSON code I return the field wbn_id as unique ID. Do I have to give the field another name, or can I somehow “attach” the wbn_id to the unique ID from the scheduler?

I use an AJAX call to send the items to the database. They return JSON code with [result: ok]. So this works, do I have to do something else in the scheduler code? Maybe something like return true; ??

Do I have to give the field another name
The simplest solution will be to rename it to the “id”
( the only way to alter expected id name - code modifications in the scheduler.js )

Maybe something like return true; ??
Your code looks mostly correct ( using clearAll and reload after each event adding may be a little bit rough, but must work correctly anyway )

I use an AJAX call to send the items to the database
To which events, such call is assigned ?

This works. I tried event_id before, but that didn’t work. This works now.

I have a function save_form() which is called from the lightbox popup when you click on save. In save_form() the AJAX is called, then I give a return true, but it doesn’t work. (Tried to put an alert() right before the return true; this is executed, so the scheduler.endLightbox() doesn’t throw an error.

It will be more safe to trigger custom data saving logic from onEventAdded and onEventChanged handlers - they are triggered when edit process is fully finished, so logic attached to them can’t break anything.

I get it, but how do I trigger onEventAdded() and onEventChanged() from a form? The onEventChanged() is already called when I drag’n’drop, but the form doesn’t submit (because it refreshed the page), but it closes and calls another function.

I can’t seem to find something like this in de examples directory.

When lightbox form closing, it must trigger one of above events.
Actually, looking at code, there is no way to skip those events, when you are pressing save button.
onEventAdded will be triggered if event was not saved to DB yet, and onEvenChanged will be triggered for already existing events.

Changed the save-call to the triggers. But didn’t work directly for me. The problem was that the form (which doesn’t close, but hides) still had the 0 value in ID when I created a new item. As soon as I tried to move an item I just placed, it checks if the ID in the form is bigger than 0, if so, it does something else. So I reset the form after every save, and now it works perfectly! Thans for your help.