Skip to main content

Clusters class

📖 Description

The Clusters class represents a collection of clusters (sections) of a form definition in the builder. Each cluster in the collection is a Cluster instance.

🗃️ Fields


🏷️ all

Retrieves all the clusters that are in the collection.

Type

Cluster[]


🏷️ branch

Retrieves the parent branch.

Type

Branch


🏷️ count

Retrieves the number of clusters in the collection.

Type

number


🏷️ firstItem

Retrieves the first cluster in the collection.

Type

Cluster | undefined


🏷️ lastItem

Retrieves the last cluster in the collection.

Type

Cluster | undefined

▶️ Methods


🔧 append

Appends a new cluster to the end of the collection.

Signature

append(): Cluster

Return value

Returns a reference to the new Cluster instance.


🔧 appendBranch

Appends a new branch cluster to the end of the collection.

Signature

appendBranch(): [Branch, Cluster]

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 appendNestedBranch

Appends a new nested branch cluster to the end of the collection.

Signature

appendNestedBranch(): [Branch, Cluster]

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 each

Iterates through all clusters in the collection.

Signature

each(fn: (cluster: Cluster) => boolean | void): boolean

Parameters

NameTypeOptionalDescription
fn(cluster: Cluster) => boolean | voidNoFunction that is called for each cluster in the collection. If you want to stop the iteration, you can return true from this function to do so.

Return value

Returns true if the iteration was stopped (break).


🔧 insert

Inserts a new cluster at the top of the collection.

Signature

insert(): Cluster

Return value

Returns a reference to the new Cluster instance.


🔧 insertAfter

Inserts a new cluster after the supplied cluster.

Signature

insertAfter(cluster: Cluster): Cluster

Parameters

NameTypeOptionalDescription
clusterClusterNoSpecifies the cluster after which the new cluster is inserted.

Return value

Returns a reference to the new Cluster instance.


🔧 insertBefore

Inserts a new cluster before the supplied cluster.

Signature

insertBefore(cluster: Cluster): Cluster

Parameters

NameTypeOptionalDescription
clusterClusterNoSpecifies the cluster for which the new cluster is inserted.

Return value

Returns a reference to the new Cluster instance.


🔧 insertBranch

Inserts a new branch cluster at the top of the collection.

Signature

insertBranch(): [Branch, Cluster]

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 insertBranchAfter

Inserts a new branch cluster after the supplied cluster.

Signature

insertBranchAfter(cluster: Cluster): [Branch, Cluster]

Parameters

NameTypeOptionalDescription
clusterClusterNoSpecifies the cluster after which the new cluster is inserted.

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 insertBranchBefore

Inserts a new branch cluster before the supplied cluster.

Signature

insertBranchBefore(cluster: Cluster): [Branch, Cluster]

Parameters

NameTypeOptionalDescription
clusterClusterNoSpecifies the cluster after which the new cluster is inserted.

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 insertNestedBranch

Inserts a new nested branch cluster at the top of the collection.

Signature

insertNestedBranch(): [Branch, Cluster]

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 insertNestedBranchAfter

Inserts a new nested branch cluster after the supplied cluster.

Signature

insertNestedBranchAfter(cluster: Cluster): [Branch, Cluster]

Parameters

NameTypeOptionalDescription
clusterClusterNoSpecifies the cluster after which the new cluster is inserted.

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 insertNestedBranchBefore

Inserts a new nested branch cluster before the supplied cluster.

Signature

insertNestedBranchBefore(cluster: Cluster): [Branch, Cluster]

Parameters

NameTypeOptionalDescription
clusterClusterNoSpecifies the cluster after which the new cluster is inserted.

Return value

Returns a reference to the new Branch and Cluster instances.


🔧 reverseEach

Iterates through all clusters in the collection in reverse direction (starting with the last cluster).

Signature

reverseEach(fn: (cluster: Cluster) => boolean | void): boolean

Parameters

NameTypeOptionalDescription
fn(cluster: Cluster) => boolean | voidNoFunction that is called for each cluster in the collection. If you want to stop the iteration, you can return true from this function to do so.

Return value

Returns true if the iteration was stopped (break).


🔧 sort

Sorts the clusters using the supplied compare function.

Signature

sort(fn: (a: Cluster, b: Cluster) => number): boolean

Parameters

NameTypeOptionalDescription
fn(a: Cluster, b: Cluster) => booleanNoSpecifies the compare function. The compare function should return a number according to the following rules:
- a is less than b return -1;
- a is greater than b return 1;
- a is equal to b return 0.

Return value

Returns true if the sort invoked a cluster position change.