Search
Events.linkCreating Property
See Also
 





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

Namespace: MindFusion.Diagramming
File: Events.js

 Syntax

JavaScript  Copy Code

get linkCreating() {}
set linkCreating(value) {}

 Property Value

String

A string containing the event name.

 Remarks

Event handlers receive a LinkEventArgs instance as argument.

 Example

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

JavaScript  Copy Code

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

diagram.addEventListener(
    Events.linkCreating, 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