NodeBlock class
đ Descriptionâ
The NodeBlock
class is what gives a Node
its actual functionality. These blocks are visual blocks that interact with the user and collect the response data for the slots that are denoted by the block.
You can create custom blocks for Tripetto. More information about custom blocks for the stock runners can be found in this Custom blocks guide.
đ Applicable decoratorsâ
The following decorators can be applied in this class:
Class decorators âšī¸â
Method decorators âšī¸â
đī¸ Fieldsâ
đˇī¸ context
â
Reference to the context of the block.
Typeâ
đˇī¸ isFailed
â
Retrieves if the validation of the block failed.
Typeâ
boolean
đˇī¸ isPassed
â
Retrieves if the validation of the block passed.
Typeâ
boolean
đˇī¸ node
â
Retrieves the node props from the form definition.
Typeâ
đˇī¸ props
â
Retrieves the block properties from the form definition.
Typeâ
{
/* Contains the node block type identifier. */
type: string;
/* Contains the version of the block. */
version: string;
}
Besides the listed properties, node blocks may store additional properties in the props
object.
đˇī¸ shouldAutoRender
â
Specifies if an automatic render is needed upon value store. This triggers a rerendering when a value is changed.
Typeâ
boolean
đˇī¸ shouldAutoValidate
â
Specifies if automatic validation is applied which checks if all required slots contain a valid value.
Typeâ
boolean
đˇī¸ type
â
Retrieves the block type object.
Typeâ
{
/* Contains the block type identifier. */
identifier: string;
/* Specifies if the block needs an automatic render upon value store. */
autoRender?: boolean;
/* Specifies if the block needs automatic validation. */
autoValidate?: boolean;
/* Reference to optional static data for the block. */
ref?: {};
}
đˇī¸ validation
â
Retrieves the validation state of the block. It can be one of the following values:
unknown
: There is no validation state available yet;pass
: Validation succeeded;fail
: Validation failed.
Typeâ
"unknown" | "pass" | "fail"
đˇī¸ 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â
đ§ clear
â
Clears all data values of a block.
Signatureâ
clear(): void
đ§ immutableValueOf
â
Retrieves the immutable (write-protected) value for the supplied slot instance or identifier.
Signatureâ
immutableValueOf(slot: Slot | string): ImmutableValue | undefined
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
slot | Slot | string | No | Specifies the slot of the value. |
Return valueâ
Returns the ImmutableValue
instance for the slot or undefined
if the supplied slot is invalid.
đ§ key
â
Retrieves a unique key for the block within the current context for the specified label (the key is prefixed with an underscore).
Use this function if you need stable unique keys (for example to use as element IDs).
Signatureâ
key(label?: string): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
label | string | Yes | Optional label for the key (if omitted the default key will be returned). |
Return valueâ
Returns the key.
đ§ lock
â
Locks the data values of a block (makes the whole block write-protected).
Signatureâ
lock(): void
đ§ parseVariables
â
Parses the supplied markdown string, replacing all variables with their current values.
This method is used to parse markdown to plain text.
Signatureâ
parseVariables(markdown: string, placeholder?: string, lineBreaks?: boolean): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
markdown | string | No | Specifies the markdown string to parse. |
placeholder | string | Yes | Specifies a string for empty variables (defaults to "" ). |
lineBreaks | boolean | Yes | Specifies if line breaks are supported (defaults to false ). |
Return valueâ
Returns the parsed string.
đ§ rerender
â
Invokes a block rerendering.
Signatureâ
rerender(): void
đ§ slotOf
â
Retrieves the slot with the specified reference.
Signatureâ
slotOf(reference: string, kind?: "static" | "dynamic" | "feature" | "meta"): Slot | undefined
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
reference | string | No | Specifies the slot reference. |
kind | "static" | "dynamic" | "feature" | "meta" | Yes | Optional kind to narrow the scope of the slot select operation. |
Return valueâ
Returns the Slot
instance or undefined
if no slot is found.
đ§ unlock
â
Unlocks the data values of a block (removes the write-protected flag from the whole block).
Signatureâ
unlock(): void
đ§ valueOf
â
Retrieves a mutable value of a slot. Use this method to set/retrieve the values of slots that belong to the block.
You can only retrieve mutable values for the slots managed by the block. If you want values from other nodes, use the immutableValueOf
method.
Signatureâ
valueOf(
reference: string,
kind?: "static" | "dynamic" | "feature" | "meta",
options?: {
confirm?: boolean;
prefill?: {
value: any;
reference?: string;
};
modifier?: (value: Value) => {
value: any;
reference?: string;
} | undefined;
onChange?: (value: Value) => void;
onContext?: (value: Value, context: Context) => void;
}
): Value | undefined
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
reference | string | No | Specifies the slot reference. |
kind | "static" | "dynamic" | "feature" | "meta" | Yes | Optional kind to narrow the scope of the slot select operation. |
options | object | Yes | Specifies additional options. Supports the following options: - confirm : Specifies if the slot always has a confirmed value;- prefill : Specifies a prefill value for the slot;- modifier : Specifies a modifier function that is invoked when the value of the slot changes and can be used to modify the value;- onChange : Specifies a function that is invoked when the value of the slot changes;- onContext : Specifies a function that is invoked when the value is used within another context. |
Return valueâ
Returns the Value
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â
Name | Type | Optional | Description |
---|---|---|---|
slot | Slot | { slot: Slot } | string | No | Specifies the slot of the variable. |
Return valueâ
Returns the IVariable
instance for the slot or undefined
if the supplied slot is invalid.