How to get go.Shape portId in onClick event

Hello, Im willing to validate connection between 2 ports and Im having hard time detecting which port I clicked on, hopefully you can shed some light on it.

Situation is:

  • Im dropping nodes from palette ( go.GraphObject.make(go.Palette… ) on canvas ( go.GraphObject.make(go.Diagram… )

  • each node is added into NodeTemplateMap, depending on node category I call portFactory function, which draws ports with particular params ( go.Shape objects )

  • each port object has onClick function which should console.log portId of that port

Im attaching below portFactory code, with my attempts.

https://pastebin.com/raw/j95ySNTd

Thank you for any suggestions

I’m not sure what your question is. The GraphObject.click event handler is passed two arguments. The second argument is that GraphObject on which the event handler was defined. So:

$(go.Shape, "Circle",
  { . . .,
    portId: . . .,
    click: function(e, shape) {
        console.log("clicked port: " + shape.portId);
    }
  })
1 Like

Id swear this was my first attempt, but I guess it was not…

Thanks !