TextField (텍스트필드) Widget Control
Example file: 07_Work_with_Widgets/textfield_objet.lfp
This page lists the Widget Controls (Property · Method · Event) you use to control the TextField widget from a script. For an introduction to the widget and how to use it, visit TextField.
In the examples below, textfieldID is the name (ID) you gave the TextField widget on the canvas. Scripts access members in the form widgetID.member.
Widget Control summary
| Widget Control | Kind | Signature | Description |
|---|---|---|---|
setText | Method | setText(text): void | Set the text and update the screen |
requestFocus | Method | requestFocus(): void | Move keyboard focus to this field |
getText | Method | getText(): string | Return the current text |
getTextWidth | Method | getTextWidth(includePadding, useHint?): number | Measure the rendered width (px) of the current text |
text | Property | string (read/write) | The text in the field |
onTap | Event | onTap = () => { ... } | When the field is tapped |
onChanged | Event | onChanged = (value) => { ... } | Every time the text changes, including each keystroke |
onTabKey | Event | onTabKey = () => { ... } | When the Tab key is pressed |
onSubmitted | Event | onSubmitted = (value) => { ... } | On submit (Enter or the action button) |
onEditingComplete | Event | onEditingComplete = () => { ... } | When editing finishes, before focus is released |
onFocusOut | Event | onFocusOut = () => { ... } | When the field loses focus |
Property
text
The text entered in the field. You can both read and write it, and reading it returns an empty string ('') when no value is set.
- Type:
string - Access: read / write
Example
textfieldID.text = "안녕하세요";
const t = textfieldID.text;
Method
setText
Sets the text of the field and updates the screen.
- Parameters
text(string): the text to set
- Returns: None (
void)
Example
textfieldID.setText("hello");
getText
Returns the current text. Returns an empty string when no value is set.
- Parameters: None
- Returns:
string- the current text (''if empty)
Example
const t = textfieldID.getText();
getTextWidth
Measures the pixel width of the current text as rendered in the field's font style. Handy for sizing the field to fit its contents.
- Parameters
includePadding(boolean): if true, adds the horizontal inner padding of the decoration (uses 24 when no padding is set)useHint(boolean, defaultfalse): if true, measures the hint text and style instead of the entered text
- Returns:
number- the text width in px
Example
const w = textfieldID.getTextWidth(true);
requestFocus
Forces keyboard focus onto this TextField. Use it when an event needs to focus the TextField immediately.
- Parameters: None
- Returns: None (
void)
Example
textfieldID.requestFocus();
Event
onChanged
Runs every time the text changes, including each keystroke.
- Handler arguments:
value(string) - the text after the change - Returns: None
Example
textfieldID.onChanged = (value) => {
// value: the changed text
};
onEditingComplete
Runs when editing finishes — for example, when the Enter key is pressed — before focus is released.
- Handler arguments: None
- Returns: None
Example
textfieldID.onEditingComplete = () => { /* ... */ };
onSubmitted
Runs when the user submits the field — for example, with Enter or the keyboard action button.
- Handler arguments:
value(string) - the submitted text - Returns: None
Example
textfieldID.onSubmitted = (value) => { /* ... */ };
onTap
Runs when the field is tapped.
- Handler arguments: None
- Returns: None
Example
textfieldID.onTap = () => { /* ... */ };
onFocusOut
Runs when the field loses keyboard focus.
- Handler arguments: None
- Returns: None
Example
textfieldID.onFocusOut = () => { /* ... */ };
onTabKey
Runs when the Tab key is pressed.
- Handler arguments: None
- Returns: None
Example
textfieldID.onTabKey = () => { /* ... */ };
Common Widget Control (all widgets)
Every widget also supports common Widget Controls (Method) such as setProperty(name, value), getProperty(name), and setStyleProperty(styleName, styleProperty, value). For the detailed rules, visit the common Widget Control reference.