Skip to main content

api.getLinkValidator()

PRO

The functionality is available in PRO Edition only

Description​

Returns a function that checks whether a link can be added

The function checks a link against the rules of auto scheduling. Gantt uses it to prevent invalid links in the UI.

Usage​

api.getLinkValidator(): (link: {
source: string | number,
target: string | number,
type: "e2s" | "s2s" | "e2e" | "s2e",
id?: string | number,
}) => "cycle" | "parent-chain" | "summary-endpoint" | null;

Returns​

A function that takes a link object and returns null if the link is valid, or the reason why it is invalid:

  • "cycle" - the link creates a circular dependency
  • "parent-chain" - the link connects a summary task and its own child task
  • "summary-endpoint" - the link starts from the start of a summary task or ends at the end of a summary task

If auto scheduling is disabled, the function always returns null. The function checks links against the current data, so get a new one after the data changes.

Example​

const validate = api.getLinkValidator();
const reason = validate({ source: 1, target: 2, type: "e2s" });

if (!reason) api.exec("add-link", { link: { source: 1, target: 2, type: "e2s" } });

Related articles: