newTextField Not Firing 'began' phase.

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.

  1. Click the text field.  ‘began’ and ‘nil’ are printed as expected.

  2. Type anything.  Each keystroke will print ‘editing’ followed by the other prints in the editing if statement.

  3. Submit or finish the editing. ‘submitted’ is printed.

  4. 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

Hi Andrew,

I’m not sure what to advise. I tested your code on an iPhone 5 and it works exactly as expected. I get the “began” phase each time I re-click on the input field after it has been de-activated.

My only addition was that I added a tap listener to the display stage to close the keyboard. Simply hitting the “return” key will not close the keyboard in this most simple case, so the input field will never become de-activated, and thus, you’ll never get the “began” phase. But, I assume you’ve done this similar type of functionality elsewhere in your code, since you mention “This will bring up the cursor and keyboard if you are not in the simulator…” which implies that you’ve closed it somehow. Correct?

Best regards,

Brent

That was exactly my problem.  In my main project I had my code in the wrong area to set the keyboard focus to nil.  I had quickly created the example code and forgotten about the keyboard focus and saw that I was getting the same problem which I then assumed that it wasn’t due to my code.  Turns out I was never getting an ‘ended’ phase which means the text field was never deactivated.  Thank you for your quick response and hopefully this post will help others who boneheadedly forget about the keyboard focus, specifically, native.setKeyboardFocus().

Respectfully,

Andrew Shaw

Hi Andrew,

I’m not sure what to advise. I tested your code on an iPhone 5 and it works exactly as expected. I get the “began” phase each time I re-click on the input field after it has been de-activated.

My only addition was that I added a tap listener to the display stage to close the keyboard. Simply hitting the “return” key will not close the keyboard in this most simple case, so the input field will never become de-activated, and thus, you’ll never get the “began” phase. But, I assume you’ve done this similar type of functionality elsewhere in your code, since you mention “This will bring up the cursor and keyboard if you are not in the simulator…” which implies that you’ve closed it somehow. Correct?

Best regards,

Brent

That was exactly my problem.  In my main project I had my code in the wrong area to set the keyboard focus to nil.  I had quickly created the example code and forgotten about the keyboard focus and saw that I was getting the same problem which I then assumed that it wasn’t due to my code.  Turns out I was never getting an ‘ended’ phase which means the text field was never deactivated.  Thank you for your quick response and hopefully this post will help others who boneheadedly forget about the keyboard focus, specifically, native.setKeyboardFocus().

Respectfully,

Andrew Shaw