beforeAdd event is not working on diagram

Hello,
I am trying to use beforeAdd event for diagram.
According to documentation (beforeAdd Event of Data Collection | DHTMLX JavaScript Diagram Docs) if i return true it will add item in data collection and on returning false it will not add item in data collection.
when i return false it gives error Uncaught TypeError: Cannot read properties of undefined (reading ‘$item’) on diagramWithEditor.js

Version used: 5.0.0

Anyone else faced this issue ?

I apologize for the delay with the reply.
Unfortunately I was not able to reproduce your issue locally.
The following snippet works well for me locally:
https://snippet.dhtmlx.com/m4gz4y7m
If the problem still occurs for you please, provide a code snippet or a complete demo, where the problem can be reconstructed.

i’m sorry, but your snipet don’t work fine if collback return false

In this case, the new element is displayed on the diagram. (But it is impossible to interact with him). An error appears in the browser console.
If you try to add an element again, the one that is frozen will disappear from the form.
Please tell me how to make sure that the element is not added to the diagram.

I apologize for the misunderstanding.

Your problem was confirmed. And will try to fix it in one of the future updates.
I’ll inform you here about any progress on this issue.
Thank you for your report.

We fixed your reported issue in the latest dhx.Diagram update (v6.0).

Now blocking the shape adding with the beforeAdd event works correctly.

You can test it in the following snippet:

https://snippet.dhtmlx.com/xhb45mwp

Please, download the latest available dhx.Diagram build from your client’s area to get this fix.

Thank you for your report.

Best regards.

1 Like