Clearing text from native.newTextField() upon input

Hi All,

I’m new to Corona SDK and lua.  I’m having trouble clearing text from the text field when the user begins input.  I’ve tried setting the text field to blank (" ") upon the start of the event but it doesn’t seem to be working for me.  Am I missing something here?  Thanks!

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local search\_field\_wrapper = display.newGroup() local search\_field = native.newTextField( 40, 85, 340, 23) search\_field.x = centerX search\_field:setTextColor( 0,0,0) search\_field.size = 1 search\_field.font = native.newFont( "PTSans-Regular", 12 ) search\_field.align = "center" search\_field\_wrapper:insert(search\_field) search\_field.startText = "Add New Student..." search\_field.text = search\_field.startText local function textListener( event ) if(event.phase == "began") then event.target.text = " " elseif(event.phase == "editing") then elseif(event.phase == "ended") then search\_field:addEventListener( "userInput", textListener) end end function scene:createScene( event ) end function scene:enterScene( event ) end function scene:exitScene( event ) end function scene:destroyScene( event ) end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

You’re assigning your inputListener inside of your listener function, so your listener function never gets called. 

BTW… native objects like this should be created in your enterScene() function.  Code sitting in the scene’s main chunk like that will only be executed once, when the module loads its initial time.

Thanks for the help!

You’re assigning your inputListener inside of your listener function, so your listener function never gets called. 

BTW… native objects like this should be created in your enterScene() function.  Code sitting in the scene’s main chunk like that will only be executed once, when the module loads its initial time.

Thanks for the help!