checkEvent bug?

I am trying to avoid adding an event handler more than once so I tried using ‘checkEvent’ as per the docs but it appears that this always returns true even when there is no handler attached?

https://snippet.dhtmlx.com/ar7n1vef

Hello @Al4

In the case of built-in events - they are already attached to the gantt, so the true returned from the checkEvent is correct behavior.

Each attached event has it’s own id, but for now you cant pass it as a parameter for checkEvent. This feature stays in our task tracker but I can’t give you any ETA when it will be implemented.

In your case, the best way is to attach events through the “flagged” function, which will check attach an event or not, it may look like this code fragment:

// You also can use the usual variable as a flag
var customAttach(){
   if(gantt.$_eventsAttached) return;

   gantt.attachEvent(....)
   gantt.$_eventsAttached = true;
}

Here is a demo(Click the “Attach Event” button a few times - the event will be attached only after the first click):
http://snippet.dhtmlx.com/5/3b8f2b8af

Thanks for the reply, it seems incorrect to me that checkEvent always returns true - what is the purpose of it if it does that? I am currently using a mechanism as below:

    if (!gantt.atuEventId) {
    
        gantt.atuEventId = gantt.attachEvent("onAfterTaskUpdate", function(id,e) {  .............

Hello @Al4,

Maybe I was a little bit unclear from my previous answer, so I will try to describe the current logic:

For now, built-in event handlers are attaching on the gantt initialization. So before gantt.init() the “checkEvent” will return false, after it will return “true”.

Here is a demo:
http://snippet.dhtmlx.com/5/744290827

Technically it’s correct behavior, and this method is used in our code in the current form.

But I agree with you, that for now, this method is “unusable” to work with, because of two reasons:

  1. there is no ability to detach “default” handlers
  2. there is no ability to pass the “attached event’s id” for the checkEvent method(like in the detachEvent).

The second feature stays in our task tracker and will be implemented in the future, unfortunately, I can’t give any ETA.

I hope that now it’s more clear for you.