Skip to main content

TextField (텍스트필드) Widget Control

info

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.

info

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 ControlKindSignatureDescription
setTextMethodsetText(text): voidSet the text and update the screen
requestFocusMethodrequestFocus(): voidMove keyboard focus to this field
getTextMethodgetText(): stringReturn the current text
getTextWidthMethodgetTextWidth(includePadding, useHint?): numberMeasure the rendered width (px) of the current text
textPropertystring (read/write)The text in the field
onTapEventonTap = () => { ... }When the field is tapped
onChangedEventonChanged = (value) => { ... }Every time the text changes, including each keystroke
onTabKeyEventonTabKey = () => { ... }When the Tab key is pressed
onSubmittedEventonSubmitted = (value) => { ... }On submit (Enter or the action button)
onEditingCompleteEventonEditingComplete = () => { ... }When editing finishes, before focus is released
onFocusOutEventonFocusOut = () => { ... }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, default false): 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)

note

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.