Dino
Dino

Reputation: 8292

JointJS link change:target triggers every time

From what I've inspected so far, the link target is never null, and that's why I am having problems. I want to trigger the event when I join my link to some point (object), I don't want to trigger it every time I move it around and not connecting it to anything. Is there any way I can override that change event? Or trigger the changes when I finish dragging my link

this.graph.on('change:target', function(cell) {
  if (cell.isLink()) {
    // Any code here will trigger every time I drag my link
    // There is no way I can add if else here to solve my problem
 }
}); 

Upvotes: 0

Views: 755

Answers (2)

vt.
vt.

Reputation: 1428

try this:

paper.on('link:disconnect', function(linkView, evt, disconnectedFromView, magnetElement, type) {
    console.log('link:disconnect', type, disconnectedFromView, magnetElement);
});

paper.on('link:connect', function(linkView, evt, connectedToView, magnetElement, type) {
    console.log('link:connect', type, connectedToView, magnetElement);
});

Upvotes: 1

Dino
Dino

Reputation: 8292

I found the solution. I was using the wrong handler for my purpose. Instead of using graph handler, I had to use paper's handler.

'cell:pointerup' - triggered when a pointer is released on a paper

  this.paper.on('cell:pointerup', function(cellView, event) {
    var cell = cellView.model;
    if (cell.isLink()){
      if (cell.get('source').id ==null || cell.get('target').id == null) {
        cell.remove();
      }
    }
  });

Upvotes: 0

Related Questions