Skip to main content

ConditionBlock class

📖 Description​

The ConditionBlock class is what gives a Condition its actual functionality.

tip

You can create custom condition blocks for Tripetto.

🎀 Applicable decorators​

The following decorators can be applied in this class:

Class decorators ℹī¸â€‹

Method decorators ℹī¸â€‹

🗃ī¸ Fields​


🏷ī¸ branch​

Retrieves the branch props from the form definition (only when there is a branch attached to the condition).

Type​

IBranch | undefined


🏷ī¸ branchRef​

Retrieves a reference to an attached branch (if any).

Type​

Branch | undefined


🏷ī¸ section​

Retrieves the section props from the form definition (only when there is a section attached to the condition).

Type​

ISection | undefined


🏷ī¸ sectionRef​

Retrieves a reference to an attached section (if any).

Type​

Section | undefined


🏷ī¸ condition​

Retrieves the condition props from the form definition.

Type​

ICondition


🏷ī¸ context​

Reference to the context of the block.

Type​

Context


🏷ī¸ node​

Retrieves the node props from the form definition (only when there is a node attached to the condition).

Type​

INode | undefined


🏷ī¸ nodeRef​

Retrieves a reference to an attached node (if any).

Type​

Node | undefined


🏷ī¸ props​

Retrieves the block properties from the form definition.

Type​

{
/* Contains the condition block type identifier. */
type: string;

/* Contains the version of the block. */
version: string;

/* Contains the id of a related branch. */
branch?: string;

/* Contains the id of a related section. */
section?: string;

/* Contains the id of a related node. */
node?: string;

/* Contains the id of a related slot. */
slot?: string;
}
info

Besides the listed properties, condition blocks may store additional properties in the props object.


🏷ī¸ slots​

Retrieves a reference to the slots collection of an attached node (only when condition is attached to a node).

Type​

Slots


🏷ī¸ type​

Retrieves the block type object.

Type​

{
/* Contains the block type identifier. */
identifier: string;
}

🏷ī¸ view​

Retrieves the current view mode of the runner. It can be one of the following values:

  • live: Normal run mode of the form;
  • test: Runs the form like a real one without being able to submit data;
  • preview: Shows all elements in the form by skipping all logic.

Type​

"live" | "test" | "preview"

â–ļī¸ Methods​


🔧 immutableValueOf​

Retrieves the immutable (write-protected) value for the supplied slot instance or identifier.

Signature​

immutableValueOf(slot?: Slot | string): ImmutableValue | undefined

Parameters​

NameTypeOptionalDescription
slotSlot | stringYesSpecifies the slot of the value. If omitted the slot specified in the slot property of the block props is returned.

Return value​

Returns the ImmutableValue instance for the slot or undefined if the supplied slot is invalid.


🔧 parseVariables​

Parses the supplied markdown string, replacing all variables with their current values.

info

This method is used to parse markdown to plain text.

Signature​

parseVariables(markdown: string, placeholder?: string, lineBreaks?: boolean): string

Parameters​

NameTypeOptionalDescription
markdownstringNoSpecifies the markdown string to parse.
placeholderstringYesSpecifies a string for empty variables (defaults to "").
lineBreaksbooleanYesSpecifies if line breaks are supported (defaults to false).

Return value​

Returns the parsed string.


🔧 slotOf​

Retrieves the slot attached to the condition (this is the slot specified in the slot property of the block props) or the slot with the specified identifier.

Signature​

slotOf(id?: string): Slot | undefined

Parameters​

NameTypeOptionalDescription
idstringNoSpecifies the identifier of the slot to retrieve. If omitted the slot specified in the slot property of the block props is returned.

Return value​

Returns the Slot instance or undefined if no slot is attached or the slot is not found.


🔧 valueOf​

Retrieves an immutable (write-protected) value. You can only retrieve values for the slots of an attached node. If you want to retrieve values from other nodes or for conditions without an attached node, use immutableValueOf.

Signature​

valueOf(slot?: Slot | string, kind?: "static" | "dynamic" | "feature" | "meta"): ImmutableValue | undefined

Parameters​

NameTypeOptionalDescription
slotSlot | stringYesSpecifies the slot of the value. If omitted the slot specified in the slot property of the block props is returned.
kind"static" | "dynamic" | "feature" | "meta"YesOptional kind to narrow the scope of the slot select operation.

Return value​

Returns the ImmutableValue instance for the slot or undefined if the supplied slot is invalid.


🔧 variableFor​

Retrieves the variable for the supplied slot instance or (pipe) identifier. A variable is an immutable representation of a slot value. This method allows to retrieve any slot value in the form within the right context. It can be used to retrieve values from other blocks as well. For example, the calculator block uses this method to retrieve input values from other blocks for the calculator.

Signature​

variableFor(slot: Slot | { slot: Slot } | string): IVariable | undefined

Parameters​

NameTypeOptionalDescription
slotSlot | { slot: Slot } | stringNoSpecifies the slot of the variable.

Return value​

Returns the IVariable instance for the slot or undefined if the supplied slot is invalid.