Skip to main content

Text class

📖 Description

The Text class defines a text input control for the Tripetto builder. It is derived from the DataControl class.

📺 Preview


🆕 constructor

Creates a new Text instance.

Signature

constructor(
type?: "singleline" | "multiline" | "multiline-wo-crlf" | "password" | "email",
value?: string | Binding,
lines?: number,
style?: ITextStyle
): Text

Parameters

NameTypeOptionalDescription
type"singleline" | "multiline" | "multiline-wo-crlf" | "password" | "email"YesSpecifies the input type (default is singleline). It can be one of the following values:
- singleline: The control accepts single line text;
- multiline: The control accepts multi line text (including hard returns);
- multiline-wo-crlf: The control input can break to a next line, but hard returns (CRLFs) are not allowed;
- password: Password input mode (input is masked);
- email: Email address input mode.
valuestring | BindingYesSpecifies the initially value or a data binding created with bind.
linesnumberYesSpecifies the minimum number of lines for multi-line input.
styleITextStyleYesSpecifies the input style (when omitted the default global style will be used).

Return value

Returns a reference to the new Text instance.

📌 Statics


🏷️ style

Contains the global default style for the input control.

Type

ITextStyle


🔧 bind

Binds an object property to the control allowing its value to update automatically when the value of the control changes. If the control is disabled or invisible, the supplied valueWhenInactive is automatically set as the property value. When a control is enabled and visible, the supplied defaultWhenActive is set automatically if the property value is currently not defined.

Signature

bind<Target, P extends keyof Target>(
target: Target,
property: P,
valueWhenInactive: string,
defaultWhenActive?: string,
modifier?: (value?: string) => string
): Binding;

Parameters

NameTypeOptionalDescription
targetTargetNoReference to the target object which contains the property.
propertyPNoSpecifies the name of the property.
valueWhenInactivestringNoSpecifies the value which is set to the property when the control is inactive (disabled or invisible).
defaultWhenActivestringYesSpecifies the default (initial) value that will be used when the control is active (enabled and visible).
modifier(value?: string) => stringYesSpecifies a modifier function for the data.

Return value

Returns a Binding instance that can be used in the controls constructor to bind a value to a control.

Example

import { Forms } from "@tripetto/builder";

const example = {
text: ""
};

const text = new Forms.Text("singleline", Forms.Text.bind(example, "text", ""));

🗃️ Fields


🏷️ hasFocus

Retrieves if the control has input focus.

Type

boolean


🏷️ isDisabled

Sets or retrieves if the control is disabled.

Type

boolean


🏷️ isLocked

Sets or retrieves if the control is locked (readonly).

Type

boolean


🏷️ isObservable

Retrieves if the control is observable.

Type

boolean


🏷️ isRequired

Sets or retrieves if the control is required.

Type

boolean


🏷️ isVisible

Sets or retrieves the visibility of the control.

Type

boolean


🏷️ style

Contains the text control style.

Type

ITextStyle


🏷️ suggestion

Retrieves the current selected suggestion.

Type

ITextSuggestion


🏷️ type

Retrieves the input type. It can be one of the following values:

  • singleline: The control accepts single line text;
  • multiline: The control accepts multi line text (including hard returns);
  • multiline-wo-crlf: The control input can break to a next line, but hard returns (CRLFs) are not allowed;
  • password: Password input mode (input is masked);
  • email: Email address input mode.

Type

"singleline" | "multiline" | "multiline-wo-crlf" | "password" | "email"


🏷️ value

Sets or retrieves the input value.

Type

string

▶️ Methods


🔧 action

Attaches an key action to the control.

info

This method can be used to implement variables support in the text control.

Signature

action(
key: string,
fn: (
done: (text?: string) => void,
text: Element
) => ((key: string) => "capture" | "cancel" | "continue") | undefined | void
): this

Parameters

NameTypeOptionalDescription
keystringNoSpecifies the key to bind the action to.
fn(done: (text?: string) => void, text: Element) => ((key: string) => "capture" | "cancel" | "continue") | undefined | voidNoSpecifies the action function to execute.

Return value

Returns a reference to the Text instance to allow chaining.

Example

import { insertVariable, Forms } from "@tripetto/builder";

// Use this code inside a block (`this` refers to the block instance)
// The `insertVariable` function will supply a list of possible variables
// when the user enters the `@` key.
new Forms.Text()
.action("@", insertVariable(this));

🔧 align

Sets the alignment of the control.

Signature

align(align: "left" | "center" | "right"): this

Parameters

NameTypeOptionalDescription
align"left" | "center" | "right"NoSpecifies the alignment.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 autoSelect

Specifies if the text needs to be selected automatically.

Signature

autoSelect(select?: "no" | "focus" | "auto-focus"): this

Parameters

NameTypeOptionalDescription
select"no" | "focus" | "auto-focus"YesSpecifies if the text needs to be selected.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 autoValidate

Enables automatic control validation.

Signature

autoValidate(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 blur

Blurs the focus of the control.

Signature

blur(): void

🔧 copyToClipboard

Copies the contents of the input control to the clipboard.

Signature

copyToClipboard(): void

🔧 disable

Disables the control.

Signature

disable(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 disabled

Specifies the state of the control.

Signature

disabled(disabled?: boolean): this

Parameters

NameTypeOptionalDescription
disabledbooleanYesSpecifies if the control is disabled (default is true).

Return value

Returns a reference to the Text instance to allow chaining.


🔧 enable

Enables the control.

Signature

enable(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 enter

Specifies the function which is invoked when the user presses the enter key.

Signature

enter(fn: (text: Text) => boolean): this

Parameters

NameTypeOptionalDescription
fn(text: Text) => booleanNoSpecifies the function to invoke. To cancel the normal behavior return true within the function.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 escape

Specifies the function which is invoked when the user presses the escape key.

Signature

escape(fn: (text: Text) => boolean): this

Parameters

NameTypeOptionalDescription
fn(text: Text) => booleanNoSpecifies the function to invoke. To cancel the normal behavior return true within the function.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 fixedLines

Sets a fixed number of lines for the control (auto-sizing will be disabled).

Signature

fixedLines(lines: number): this

Parameters

NameTypeOptionalDescription
linesnumberNoSpecifies the number of lines.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 focus

Sets the focus to the control.

Signature

focus(): boolean

Return value

Returns true if the focus is set.


🔧 hide

Hides the control.

Signature

hide(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 indent

Enables control indentation. This can only be set during construction.

Signature

indent(size: number): this

Parameters

NameTypeOptionalDescription
sizenumberNoSpecifies the indent size in pixels.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 inputMode

Sets the input mode for the text control.

Signature

inputMode(mode: "text" | "decimal" | "numeric" | "tel" | "search" | "email" | "url"): this

Parameters

NameTypeOptionalDescription
mode"text" | "decimal" | "numeric" | "tel" | "search" | "email" | "url"NoSpecifies the mode.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 label

Sets the label for the control.

tip

If you want to use markdown in the label, activate it first using the markdown method.

Signature

label(label: string): this

Parameters

NameTypeOptionalDescription
labelstringNoSpecifies the control label.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 lock

Locks the control.

Signature

lock(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 locked

Specifies if the control is locked (readonly).

Signature

locked(locked?: boolean): this

Parameters

NameTypeOptionalDescription
lockedbooleanYesSpecifies if the control is locked/readonly (default is true).

Return value

Returns a reference to the Text instance to allow chaining.


🔧 markdown

Specifies if the label should support markdown formatting.

Signature

markdown(options?: IMarkdownOptions): this

Parameters

NameTypeOptionalDescription
optionsIMarkdownOptionsYesSpecifies the markdown options.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 maxLength

Specifies the maximum text length.

Signature

maxLength(maxLength: number): this

Parameters

NameTypeOptionalDescription
maxLengthnumberNoSpecifies the maximum text length (supply 0 to disable the maximum length).

Return value

Returns a reference to the Text instance to allow chaining.


🔧 name

Sets a name for the text control.

Signature

name(name: string): this

Parameters

NameTypeOptionalDescription
namestringNoSpecifies the name.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 on

Specifies the function which is invoked when the input value changes.

Signature

on(fn: (text: Text) => void): this

Parameters

NameTypeOptionalDescription
fn(text: Text) => voidNoSpecifies the change function.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 placeholder

Sets a placeholder for the text control.

Signature

placeholder(placeholder: string): this

Parameters

NameTypeOptionalDescription
placeholderstringNoSpecifies the placeholder text.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 readonly

Makes the control readonly.

Signature

readonly(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 require

Makes the control required.

Signature

require(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 required

Specifies if the control is required.

Signature

required(required?: boolean): this

Parameters

NameTypeOptionalDescription
requiredbooleanYesSpecifies if the control is required (default is true).

Return value

Returns a reference to the Text instance to allow chaining.


🔧 sanitize

Specifies if string sanitizing should be applied.

Signature

sanitize(sanitize?: boolean): this

Parameters

NameTypeOptionalDescription
sanitizebooleanYesSpecifies if string sanitizing should be applied.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 select

Selects the text.

Signature

select(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 show

Shows the control.

Signature

show(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 suggestions

Specifies text suggestions for the text control.

Signature

suggestions(suggestions?: (ITextSuggestion | string)[]): this

Parameters

NameTypeOptionalDescription
suggestions(ITextSuggestion | string)[]YesSpecifies the list of suggestions.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 transformation

Specifies the text transformation.

Signature

transformation(transformation: Transformations): this

Parameters

NameTypeOptionalDescription
transformation"none" | "capitalize" | "capitalize-words" | "capitalize-sentences" | "uppercase" | "lowercase"NoSpecifies the transformation type.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 trim

Specifies if string trim should be applied.

Signature

trim(trim?: boolean): this

Parameters

NameTypeOptionalDescription
trimbooleanYesSpecifies if string trimming should be applied.

Return value

Returns a reference to the Text instance to allow chaining.


🔧 unlock

Unlocks the control.

Signature

unlock(): this

Return value

Returns a reference to the Text instance to allow chaining.


🔧 visible

Specifies the visibility of the control.

Signature

visible(visible?: boolean): this

Parameters

NameTypeOptionalDescription
visiblebooleanYesSpecifies if the control is visible (default is true).

Return value

Returns a reference to the Text instance to allow chaining.


🔧 width

Sets the width of the control.

Signature

width(width: number): this

Parameters

NameTypeOptionalDescription
widthnumberNoSpecifies the control width in pixels.

Return value

Returns a reference to the Text instance to allow chaining.

⛓️ Interfaces


🔗 ITextStyle

Describes the interface for the input styles.

Type declaration

interface ITextStyle {
/* Text input appearance. */
appearance?: IStyles;

/* Text input label. */
label?: IStyles;

/* Text input disabled. */
disabled?: IStyles;

/* Placeholder style. */
placeholder?: IStyles;

/* Contains the text selection styles. */
selection?: IStyles;

/* Text input required. */
required?: IStyles;

/* Text input locked. */
locked?: IStyles;

/* Text input focus. */
focus?: IStyles;

/* Text input hover. */
hover?: IStyles;

/* Validation passed. */
passed?: IStyles;

/* Validation failed. */
failed?: IStyles;

/* Validation awaiting. */
awaiting?: IStyles;

/* Text input when fused with form card. */
fused?: {
/* Text input appearance. */
appearance?: IStyles;

/* Text input label. */
label?: IStyles;

/* Text input required. */
required?: IStyles;

/* Text input locked. */
locked?: IStyles;

/* Text input focus. */
focus?: IStyles;

/* Text input hover. */
hover?: IStyles;

/* Validation passed. */
passed?: IStyles;

/* Validation failed. */
failed?: IStyles;

/* Validation awaiting. */
awaiting?: IStyles;
};
}

🔗 ITextSuggestion

Describes the interface for the text suggestions.

Type declaration

interface ITextSuggestion {
/* Text suggestion identifier. */
id?: string;

/* Text suggestion name. */
name: string;
}