Search
DiagramBase.linkCreating Event
See Also
 





A validation event raised while the user is drawing a new link.

Namespace: MindFusion.Diagramming
File: DiagramBase.js

 Syntax

JavaScript  Copy Code
diagram.linkCreating.addEventListener(onLinkCreating);

 Event Data

Event handlers receive a LinkEventArgs instance containing data about this event.

 Example

This example shows how to handle the linkCreating event to prevent cycles in the graph.

JavaScript  Copy Code

// assuming namespaced scripts
var PathFinder = MindFusion.Diagramming.PathFinder;

diagram.linkCreating.addEventListener(onLinkCreating);

function onLinkCreating(diagram, args)
{
    if (args.destination == null)
    {
        // not pointing to a node yet
        return;
    }

    var pathFinder = new PathFinder(diagram);
    var path = pathFinder.findShortestPath(
        args.destination, args.origin);

    if (path != null)
    {
        // adding this new link would create a cycle
        // [origin]--[dest]--[path internal nodes]--[origin]

        args.cancel = true;
    }
}

 See Also