text([text], [action], [insert_position])
Class: ToolBar. Method inherited from UIComponent.
Description:
Sets or gets text content of the component. Even though some components don't show text, you can still set text to it.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
|
|
string |
Can be plain text or HTML. HTML is only supported in some components (e.g. Label, Button, TextDocument, ...) and should be surrounded with HTML tags. Check example below. |
|
|
|
TextAction.Set |
Specific action to perform with text. Replace, append, prepend, or insert. Applies only to some components. Do not use this argument for HTML content. |
|
|
|
number |
Position where to insert text. Applies only if |
Returns:
Returns text value if no argument is set, otherwise returns this component.
Type: string | this
Examples:
const txt = textfield.text(); // gets text value
textfield.text("New Text"); // sets new text value
textfield.text("Appended Text", TextAction.Append); // Appends new text to the end of current text
textfield.text("Inserted Text", TextAction.Insert); // Inserts at current caret position
textfield.text("Inserted Text", TextAction.Insert, textfield.caretPosition() - 50); // Inserts at specified position
textfield.text("New Text", TextAction.ReplaceSelection); // Replaces selected text or inserts at current cursor position if no text is selected (applies only to text editing components, like TextField, TextArea, ...).
