jsplumb / community-edition

The community edition of jsPlumb, versions 1.x - 6.x
https://jsplumbtoolkit.com
Other
225 stars 18 forks source link

Before Drop event called AFTER Connection Moved event #89

Open Legendary4226 opened 1 year ago

Legendary4226 commented 1 year ago

Hi 👋, I need help as explained in the title. I need to do some checks BEFORE the connection is dropped, for example : "Check if the two elements (source and target) are already connected ?"

How I proceed : Call instance.getConnections({}, true) between the source and target. Place result in a var. Check if var.lenght > 0 then a connection between the two elements already exists.

But it can't work because (and I checked) the EVENT_CONNECTION_MOVED is firered BEFORE INTERCEPT_BEFORE_DROP.

I need multiple connections enabled but not multiple between two same endpoints.

Do you have any ideas or did the event fire order needs to be changed ?

Thank's

Edit: I'm using the 6.0.5 version of JSPlumb

Legendary4226 commented 1 year ago

Up ?

sporritt commented 1 year ago

does the before drop interceptor not have the information you need in order to determine whether or not the drop should be allowed?

Legendary4226 commented 1 year ago

Hi,

I've searched a lot and couldn't tell to differentiate if the connection was moved or created. And I can't tell if the drop should be allowed because the connection is already created! "var.lenght" returns 2 and not 1.

But now I've tried using "maxConnection" when setting up endpoints, but I couldn't find out what event was fired (e.g. to replace the connection or alert the user), and the docs don't say much a lot about max connections.

Am I being clear in my explanations ?

sporritt commented 1 year ago

"And I can't tell if the drop should be allowed because the connection is already created! "var.lenght" returns 2 and not 1"

I don't mean to be flippant but can you not just test for var.length < 2 ?

Legendary4226 commented 1 year ago

No :( It's not consistent with what I want to do

Is there any way of knowing whether the connection affected by the event already exists or is created by this action ?