I’ve found what I believe to be a bug but I want to verify this isn’t working as planned. The native.newTextField’s listener does not get called when a text field already has text in it and is reclicked on after a submitted phase. To recreate what I am seeing follow the steps bellow.
-
Click the text field. ‘began’ and ‘nil’ are printed as expected.
-
Type anything. Each keystroke will print ‘editing’ followed by the other prints in the editing if statement.
-
Submit or finish the editing. ‘submitted’ is printed.
-
Up to now, everything is as expected. Now click on the text box again. This will bring up the cursor and keyboard if you are not in the simulator. No began phase is printed. This is a big problem for my project as I need code to be ran when the keyboard is brought up. I can recreate this problem on the windows simulator, mac simulator and iOS devices. newTextField is working fine on Android. My windows simulator is on daily build 2015.2697 the latest build as of this writing.
Please let me know if I need to fill out a bug report or if this working as intended. Below is the test code made to test this problem. It is the exact code from the Docs page with one added print statement at the top to show the phase when the listener is entered.
[lua]
local defaultField
local function textListener( event )
print( event.phase)
if ( event.phase == “began” ) then
– user begins editing defaultField
print( event.text )
elseif ( event.phase == “ended” or event.phase == “submitted” ) then
– do something with defaultField text
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 )[/lua]
Respectfully,
Andrew Shaw
Vice President
AF4 Studios