Type Function
Library native.*
Return value TextField
Revision Current Public Release (2014.2511)
Keywords text input, text fields, native text
See also native.newTextBox()
userInput events


Creates a single-line text field for text input.

Native text fields can listen for userInput events (see example).

Native text fields can display optional placeholder text (nil by default). This can provide a "hint" as to what the user should enter in the field. If set, the placeholder string is displayed using the same style information (except the text color). The placeholder does not appear once actual text has been input into the field and it does not currently participate in determining the size of the text field.



native.newTextField( centerX, centerY, width, height )
centerX, centerY (required)

Numbers. The x and y coordinates that correspond to the center of the text field.

width, height (required)

Numbers. Width and height (size) of the text field.

Functions and Properties

See the TextField documentation for a list of functions and properties.


local defaultField

local function textListener( event )

    if ( event.phase == "began" ) then

        -- user begins editing text field
        print( event.text )

    elseif ( event.phase == "ended" or event.phase == "submitted" ) then

        -- text field loses focus
        -- do something with defaultField's text
        print( "Submitted text: " .. )

    elseif ( event.phase == "editing" ) then

        print( event.newCharacters )
        print( event.oldText )
        print( event.startPosition )
        print( event.text )


-- Create text field
defaultField = native.newTextField( 150, 150, 180, 30 )

defaultField:addEventListener( "userInput", textListener )
Numeric Input Only
local function handlerFunction( event )

    if ( event.phase == "began" ) then

        -- user begins editing text field
        print( event.text )

local numericField = native.newTextField( 150, 150, 220, 36 )
numericField.inputType = "number"

numericField:addEventListener( "userInput", handlerFunction )