event.text

Type String
Event userInput
Revision Release 2022.3683
Keywords userInput, text
See also event.target
native.newTextBox()
native.newTextField()

Overview

The text content of the TextField or TextBox.

Gotchas

This property is only available during the "editing" phase of userInput events. On a phase of "submitted" or "ended", use event.target.text to access the input object's text contents.

Example

local defaultField

local function textListener( event )

    if ( event.phase == "began" ) then
        -- User begins editing "defaultField"

    elseif ( event.phase == "ended" or event.phase == "submitted" ) then
        -- Output resulting text from "defaultField"
        print( event.target.text )

    elseif ( event.phase == "editing" ) then
        print( event.newCharacters )
        print( event.oldText )
        print( event.startPosition )
        print( event.text )
    end
end

-- Create text field
defaultField = native.newTextField( 150, 150, 180, 30 )
defaultField:addEventListener( "userInput", textListener )