native.newTextField calls event.phase == "submitted" twice?

I am making a text field on a Google Nexus 4. 

Upon hitting the go button the event.phase == “submitted” is being called two times and the event.phase == “ended” is being called once. All on the submission of my text input. 

I should mention that this worked fine until I upgraded to the latest build of corona.

Any idea what is going on? And even if it where not calling submitted twice, why is  it calling both submitted and ended?

Out put is

–>POPUP Submitted!

–>POPUP Submitted!

–>POPUP Ended!

Relevant code is: 

 --Text listener for Raiding Party name local function textListener( event ) local newSceneOptions if ( event.phase == "began" ) then transition.to(popUpWindow, { time = popUpVars.transitionTime, y = popUpVars.popUpWindowPositionXY[2] - popUpVars.positionTransitionOffset, transition = easing.outCubic, }) -- user begins editing text field print( event.text ) elseif ( event.phase == "ended" ) then print("POPUP Ended!") -- text field loses focus transition.to(popUpWindow, { time = popUpVars.transitionTime, y = popUpVars.popUpWindowPositionXY[2], transition = easing.outCubic, }) native.setKeyboardFocus( nil ) startButtonGroup.startButton:setEnabled( true ) elseif ( event.phase == "submitted" ) then print("POPUP Submitted!") transition.to(popUpWindow, { time = popUpVars.transitionTime, y = popUpVars.popUpWindowPositionXY[2], transition = easing.outCubic, }) native.setKeyboardFocus( nil ) startButtonGroup.startButton:setEnabled( true ) end end if systemOs ~= "Win" then --Create text field textInputField = native.newTextField( .5\*popUpWindow.popUpBackground.width, popUpVars.textWindowPositionY, gameUi.menusImageVars.textWindowWidthHeight[1], 50 ) textInputField.placeholder = "name" textInputField.align = "center" --textInputField.text = "Fabel Gullie" textInputField.size = 20 textInputField.hasBackground = false --textInputField.font = native.newFont( "lootRaiders2", popUpVars.textPosition2FontSize ) textInputField:setTextColor( 0, 0, 0 ) textInputField:setReturnKey("go") textInputField:addEventListener( "userInput", textListener ) popUpWindow:insert( textInputField ) else --This must be on windows transitionTest() end

Hi @gullie667,

Which specific build do you mean by “latest build”?

Brent

The build I that I am using is 2014.2511 (2014.11.18)

I can’t be sure which build I was using before this one where it worked. The input field is only used once in my game on new players and I haven’t tested that in quite a while.

To ensure clarity, the “submitted” was only being called once on pushing the native keyboard’s “OK” button. I am not sure what the “ended” phase was doing as the result was as expected.

Hi @gullie667,

Can you update your code to follow the example shown in the docs?

http://docs.coronalabs.com/api/library/native/newTextField.html

Thanks,

Brent

Do you mean like this?

Note that I changed the code to work even if called to much.

Output is now: 

POPUP Submitted = submitted

POPUP Submitted = submitted

POPUP Submitted = ended

 --Text listener for Raiding Party name local function textListener( event ) if ( event.phase == "began" ) then transition.to(popUpWindow, { time = popUpVars.transitionTime, y = popUpVars.popUpWindowPositionXY[2] - popUpVars.positionTransitionOffset, transition = easing.outCubic, }) print( event.text ) elseif ( event.phase == "ended" or event.phase == "submitted" ) then print("POPUP Submitted = ", event.phase ) native.setKeyboardFocus( nil ) transition.to(popUpWindow, { time = popUpVars.transitionTime, y = popUpVars.popUpWindowPositionXY[2], transition = easing.outCubic, }) if timesSubmittedCalled == 0 then --Switch Start Button to Go Button startButtonGroup:toFront() startButtonGroup.goButton:toFront() sf.updateTextWithEffects( startButtonGroup.text, gameUi.stringLocalization.go, nil ) startButtonGroup.goButton:setEnabled( true ) timesSubmittedCalled = timesSubmittedCalled + 1 end end end if systemOs ~= "Win" then --Create text field textInputField = native.newTextField( .5\*popUpWindow.popUpBackground.width, popUpVars.textWindowPositionY, gameUi.menusImageVars.textWindowWidthHeight[1], 50 ) textInputField.placeholder = "name" textInputField.align = "center" textInputField.size = 20 textInputField.hasBackground = false textInputField:setTextColor( 0, 0, 0 ) textInputField:setReturnKey("go") textInputField:addEventListener( "userInput", textListener ) popUpWindow:insert( textInputField ) else --This must be on windows transitionTest() end

Hi @gullie667,

I tested your code in #2511 and I’m not getting duplicate events. I think you must have accidentally added two event listeners to the object… that’s the only realistic answer, because I can’t duplicate what you state is happening, using your exact code.

Best regards,

Brent

Sorry it has taken me so long to get back to this… I’ve been working one other parts of the game… 

Anyway, 

I added some print statements to check for redundancy and to ensure that nothing is being called twice. It doesn’t appear that this is the case. Also, submitted is called 2x and ended only 1x. If there where double “submitted” states due to double listeners or something then there would also be double “ended” states right? In any case, native.newTextField is only called once.

Either way… I was handling every thing on the “submitted” phase. Simply handling it on the “ended” phase solves my issuse w/o the need for a hack. 

Cheers,

Ran into the same issue, but using the ended phase would also submit the text when a user wants to back out in my case. Here is what I did to get around this, but it isn’t the most ideal solution. Brent, has anyone looked into this?

Also, running the same release (Version 2014.2511 (2014.11.18))

local textField local textBool = false   local function textFieldListener(event)     if textBool == true then         return true     elseif event.phase == 'submitted' then         textBool = true         --Do whatever with the text        timer.performWithDelay(500, function() textBool=false end)     end end   textField = ....

Hi @gullie667,

Which specific build do you mean by “latest build”?

Brent

The build I that I am using is 2014.2511 (2014.11.18)

I can’t be sure which build I was using before this one where it worked. The input field is only used once in my game on new players and I haven’t tested that in quite a while.

To ensure clarity, the “submitted” was only being called once on pushing the native keyboard’s “OK” button. I am not sure what the “ended” phase was doing as the result was as expected.

Hi @gullie667,

Can you update your code to follow the example shown in the docs?

http://docs.coronalabs.com/api/library/native/newTextField.html

Thanks,

Brent

Do you mean like this?

Note that I changed the code to work even if called to much.

Output is now: 

POPUP Submitted = submitted

POPUP Submitted = submitted

POPUP Submitted = ended

 --Text listener for Raiding Party name local function textListener( event ) if ( event.phase == "began" ) then transition.to(popUpWindow, { time = popUpVars.transitionTime, y = popUpVars.popUpWindowPositionXY[2] - popUpVars.positionTransitionOffset, transition = easing.outCubic, }) print( event.text ) elseif ( event.phase == "ended" or event.phase == "submitted" ) then print("POPUP Submitted = ", event.phase ) native.setKeyboardFocus( nil ) transition.to(popUpWindow, { time = popUpVars.transitionTime, y = popUpVars.popUpWindowPositionXY[2], transition = easing.outCubic, }) if timesSubmittedCalled == 0 then --Switch Start Button to Go Button startButtonGroup:toFront() startButtonGroup.goButton:toFront() sf.updateTextWithEffects( startButtonGroup.text, gameUi.stringLocalization.go, nil ) startButtonGroup.goButton:setEnabled( true ) timesSubmittedCalled = timesSubmittedCalled + 1 end end end if systemOs ~= "Win" then --Create text field textInputField = native.newTextField( .5\*popUpWindow.popUpBackground.width, popUpVars.textWindowPositionY, gameUi.menusImageVars.textWindowWidthHeight[1], 50 ) textInputField.placeholder = "name" textInputField.align = "center" textInputField.size = 20 textInputField.hasBackground = false textInputField:setTextColor( 0, 0, 0 ) textInputField:setReturnKey("go") textInputField:addEventListener( "userInput", textListener ) popUpWindow:insert( textInputField ) else --This must be on windows transitionTest() end

Hi @gullie667,

I tested your code in #2511 and I’m not getting duplicate events. I think you must have accidentally added two event listeners to the object… that’s the only realistic answer, because I can’t duplicate what you state is happening, using your exact code.

Best regards,

Brent

Sorry it has taken me so long to get back to this… I’ve been working one other parts of the game… 

Anyway, 

I added some print statements to check for redundancy and to ensure that nothing is being called twice. It doesn’t appear that this is the case. Also, submitted is called 2x and ended only 1x. If there where double “submitted” states due to double listeners or something then there would also be double “ended” states right? In any case, native.newTextField is only called once.

Either way… I was handling every thing on the “submitted” phase. Simply handling it on the “ended” phase solves my issuse w/o the need for a hack. 

Cheers,

Ran into the same issue, but using the ended phase would also submit the text when a user wants to back out in my case. Here is what I did to get around this, but it isn’t the most ideal solution. Brent, has anyone looked into this?

Also, running the same release (Version 2014.2511 (2014.11.18))

local textField local textBool = false   local function textFieldListener(event)     if textBool == true then         return true     elseif event.phase == 'submitted' then         textBool = true         --Do whatever with the text        timer.performWithDelay(500, function() textBool=false end)     end end   textField = ....

I also ran in to the same issue and it is a real issue that only occurs on Android devices. Works perfectly on the simulator and on iOS devices, but on the actual Android device (mine’s a Samsung Galaxy Tab), it definitely calls “submitted” twice and “ended” only once.

Hello @robert.phillips,

Have you explored the example in the docs which shows the ended and submitted phase being handled in the same conditional clause? These phases are fairly similar in terms of taking some action when they occur.

http://docs.coronalabs.com/api/library/native/newTextField.html

Best regards,

Brent

Hi Brent,

I’m an experienced Corona developer and very used to event phases.

If I log the event phase to the console using an Android device connected via USB cable in debugging mode using adb (Android Debug Bridge), it definitely logs "submitted’ twice for only one press of the keyboard “go” button.

Just as reported by gullie667, after pressing the “go” button only once, the console logs:

submitted

submitted

ended

This only occurs on an Android device and does not occur in the Corona simulator or on an actual iOS device using exactly the same code.

I can submit this as a bug if you wish, but it’s a definite problem that can only be overcome using code like that posted above by Justin as there is no other way to filter the events because the calling object and phase are identical for both of the duplicate event calls.

Regards,

Rob

Can we get you to go ahead and file a bug report please?

Thanks

Rob

Hi @robert.phillips,

We actually can’t reproduce this issue on three different Android test devices. It’s possible that you accidentally created dual listeners in your code. If you can reproduce this exact same behavior using our sample “NativeKeyboard” project, then we can investigate further. Otherwise this is not a reproducable issue at this time.

Thanks,

Brent