linkValidation and port text binding


I need to create a validation that checks if out port text is the same as in port text.

My ports are defined in nodeTemplate as:
{stroke: “black”, alignment: go.Spot.Center, editable: true, isMultiline: false},
new go.Binding(“text”, “lname”))

and on the screen I can populate lname - all works fine. Then I link the validation function:
diagram.toolManager.linkingTool.linkValidation = sameName;

function sameName(fromnode, fromport, tonode, toport) {

The problem is: how do I access the lname text value from fromport and toport parameters?
Debugger does not revel this question, I also couldn’t find any similar example in tutorials.


Your ports (TextBlocks) do not have GraphObject.portId set or data bound, so those TextBlocks are not acting as ports. Perhaps the text is inside some Panel that is declared to be a port?

The validation predicate is given the fromport and toport arguments that are references to the actual ports being considered for linking. If the ports really are your TextBlocks, you would just need to compare fromport.text === toport.text. If the TextBlock is inside a Panel that is the actual port element, you could use either Panel.elt or Panel.findObject (if the TextBlock had a to get the TextBlock and then its TextBlock.text property.