textfield Component

Use the textfield component to display an editable text input field.

{
  "type": "textfield",
  "text": "Hello!"
}

Properties

multiline
BOOL
Default: false

Allows newlines to be inserted into the text field with ⌥↩︎ or ⇧↩︎.

text
STRING [getter]

The text for this text field.

font
FONT | null
null sets the default font

The FONT for this text fields's text.

colour
COLOUR | null
null sets the default text colour

The text COLOUR.

bordered
BOOL
Default: true

Set if this text field has a border or not.

background
COLOUR | null
null removes the background

The background COLOUR.

textinsets
OBJECT

A horizontal and vertical inset around the text.

horizontal
INTEGER
Default: 2, Range: 0-64

The inset on the left and right of the text.

vertical
INTEGER
Default: 4, Range: 0-64

The inset at the top and bottom of the text. Changing this will affect the calculated height of this text field.

focusring
BOOL
Default: true

If the focus ring is drawn when focused.

placeholdercolour
COLOUR | null
null sets the placeholder text colour

The text COLOUR.

placeholder
STRING

Set the placeholder text for when the textfield is empty.

editable
BOOL

If the text in this text field is editable.

selectable
BOOL

If the text in this text field is selectable.

linebreak
"scroll" | "wrap"
Default: "scroll"

Behaviour when the text reaches the end of the line.

Value Description
"scroll" Scroll horizontally.
"wrap" Wrap the text on to a new line.

Also see Shared Properties.

Event Triggers

This component dispatches the following event triggers:

Trigger Description
"actioned" When the user presses return on the textfield.
"changed" When the text changes via user input.
"typingstopped" When the user stops typing in the textfield.

Examples

Custom text field layout with button

This example represents a composite UI which centres the custom text field component and includes a button which clears the text when pressed.

{
  "constraints": {
    "position": "centre"
  },
  "type": "view",
  "layout": "border",
  "cornerradius": 16,
  "padding": 16,
  "background": "#121212",
  "components": [
    {
      "id": "theTextField",
      "type": "textfield",
      "text": "Hello!",
      "font": {
        "size": 20
      },
      "bordertype": "none",
      "background": null,
      "focusring": false
    },
    {
      "constraints": {
        "position": "right"
      },
      "type": "button",
      "text": "Clear",
      "events": [
        {
          "triggers": "actioned",
          "action": {
            "type": "json",
            "src": {
              "update": {
                "ids": {
                  "theTextField": {
                    "text": ""
                  }
                }
              }
            }
          }
        }
      ]
    }
  ]
}