Readonly on timeline section

Hi,
I’m trying to implement readonly behaviour on timeline section.
To do this i do a control on the onBeforeLightbox event.
I grab the event with the id.
Then from the event i grab the section
I control if the field codCom in my section is GRPDEF.
If it is i delete the event newly created and return false in order to not open the lightbox.

    scheduler.attachEvent("onBeforeLightbox", function (id) {
        var ev = scheduler.getEvent(id);
        // Blocage de l'ouverture de la lightbox si la section est GRPDEF
        var sectionControl = scheduler.getSection(ev.section_id);
        if (sectionControl.codCom === 'GRPDEF') {
            ignoreDelete = true;
            scheduler.deleteEvent(ev.id); 
            return false;
        } else{
            return true;
        }
        
    });

This is working fine but it is returning an error in dhtmlxscheduler_readonly.js. (i’m using it for specific event control)
It seems that after the end of the onBeforeLightbox event he kept going throught others events.
If i follow the stack:

 Uncaught TypeError: Cannot read property 'readonly' of undefined
(anonymous function)
obj.eventCatcher.z
obj.callEvent
scheduler.showLightbox
scheduler._on_mouse_up
scheduler.addEventNow
(anonymous function)
obj.eventCatcher.z
obj.callEvent
scheduler.dblclick_dhx_matrix_cell
scheduler._on_dbl_click

Is there a way to stop the propagation right after the onBeforeLightbox event?
because it is searching for an event that i just deleted :wink:

thanks

Hi,
probably there should be a way to prevent creating of an event from the start,
however, for the approach with onBeforeLightbox event you can do a following workaround - call ‘scheduler.deleteEvent’ after a small timeout, so it will be deleted after all handlers of the readonly extension will finish working

setTimeout(function(){ scheduler.deleteEvent(ev.id); },1); return false;

Thanks for the trick. Unfortunatly it’s not that efficient because the event can be catch and drag during this small laps of time. I’ll follow your first advise and try to kill the event before it’s creation.

Thanks again