Skip to main content

Sections class

📖 Description​

The Sections class represents a collection of sections of a form definition in the builder. Each section in the collection is a Section instance.

🗃️ Fields​


🏷️ all​

Retrieves all the sections that are in the collection.

Type​

Section[]


🏷️ branch​

Retrieves the parent branch.

Type​

Branch


🏷️ count​

Retrieves the number of sections in the collection.

Type​

number


🏷️ firstItem​

Retrieves the first section in the collection.

Type​

Section | undefined


🏷️ lastItem​

Retrieves the last section in the collection.

Type​

Section | undefined

▶️ Methods​


🔧 append​

Appends a new section to the end of the collection.

Signature​

append(): Section

Return value​

Returns a reference to the new Section instance.


🔧 appendBranch​

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

Signature​

appendBranch(): [Branch, Section]

Return value​

Returns a reference to the new Branch and Section instances.


🔧 appendNestedBranch​

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

Signature​

appendNestedBranch(): [Branch, Section]

Return value​

Returns a reference to the new Branch and Section instances.


🔧 each​

Iterates through all sections in the collection.

Signature​

each(fn: (section: Section) => boolean | void): boolean

Parameters​

NameTypeOptionalDescription
fn(section: Section) => boolean | voidNoFunction that is called for each section 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 section at the top of the collection.

Signature​

insert(): Section

Return value​

Returns a reference to the new Section instance.


🔧 insertAfter​

Inserts a new section after the supplied section.

Signature​

insertAfter(section: Section): Section

Parameters​

NameTypeOptionalDescription
sectionSectionNoSpecifies the section after which the new section is inserted.

Return value​

Returns a reference to the new Section instance.


🔧 insertBefore​

Inserts a new section before the supplied section.

Signature​

insertBefore(section: Section): Section

Parameters​

NameTypeOptionalDescription
sectionSectionNoSpecifies the section for which the new section is inserted.

Return value​

Returns a reference to the new Section instance.


🔧 insertBranch​

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

Signature​

insertBranch(): [Branch, Section]

Return value​

Returns a reference to the new Branch and Section instances.


🔧 insertBranchAfter​

Inserts a new branch section after the supplied section.

Signature​

insertBranchAfter(section: Section): [Branch, Section]

Parameters​

NameTypeOptionalDescription
sectionSectionNoSpecifies the section after which the new section is inserted.

Return value​

Returns a reference to the new Branch and Section instances.


🔧 insertBranchBefore​

Inserts a new branch section before the supplied section.

Signature​

insertBranchBefore(section: Section): [Branch, Section]

Parameters​

NameTypeOptionalDescription
sectionSectionNoSpecifies the section after which the new section is inserted.

Return value​

Returns a reference to the new Branch and Section instances.


🔧 insertNestedBranch​

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

Signature​

insertNestedBranch(): [Branch, Section]

Return value​

Returns a reference to the new Branch and Section instances.


🔧 insertNestedBranchAfter​

Inserts a new nested branch section after the supplied section.

Signature​

insertNestedBranchAfter(section: Section): [Branch, Section]

Parameters​

NameTypeOptionalDescription
sectionSectionNoSpecifies the section after which the new section is inserted.

Return value​

Returns a reference to the new Branch and Section instances.


🔧 insertNestedBranchBefore​

Inserts a new nested branch section before the supplied section.

Signature​

insertNestedBranchBefore(section: Section): [Branch, Section]

Parameters​

NameTypeOptionalDescription
sectionSectionNoSpecifies the section after which the new section is inserted.

Return value​

Returns a reference to the new Branch and Section instances.


🔧 reverseEach​

Iterates through all sections in the collection in reverse direction (starting with the last section).

Signature​

reverseEach(fn: (section: Section) => boolean | void): boolean

Parameters​

NameTypeOptionalDescription
fn(section: Section) => boolean | voidNoFunction that is called for each section 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 sections using the supplied compare function.

Signature​

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

Parameters​

NameTypeOptionalDescription
fn(a: Section, b: Section) => 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 section position change.