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

Hi Brent,

I was not able to reproduce this using the “NativeKeyboard” project until I set the return key type to “go” or “send” using passwordField:setReturnKey(“go”). Setting the return key to “next” or anything else seems to only call “submitted” once, but when it is set to “go” or “send” then “submitted” is called twice.

My findings for all Android compatible settings are as follows:

“done” = OK

“go” = SUBMITTED CALLED TWICE

“next” = OK

“search” = OK

“send” = SUBMITTED CALLED TWICE

“none” = OK

Is this the intended behaviour of the “go” and “send” settings or is it a bug?

For anyone else experiencing this problem, avoid setting your final textfield’s submit button to “go” or “send” and use “done” instead.

Regards,

Rob

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

Hi Brent,

I was not able to reproduce this using the “NativeKeyboard” project until I set the return key type to “go” or “send” using passwordField:setReturnKey(“go”). Setting the return key to “next” or anything else seems to only call “submitted” once, but when it is set to “go” or “send” then “submitted” is called twice.

My findings for all Android compatible settings are as follows:

“done” = OK

“go” = SUBMITTED CALLED TWICE

“next” = OK

“search” = OK

“send” = SUBMITTED CALLED TWICE

“none” = OK

Is this the intended behaviour of the “go” and “send” settings or is it a bug?

For anyone else experiencing this problem, avoid setting your final textfield’s submit button to “go” or “send” and use “done” instead.

Regards,

Rob

I ran into this problem as well.

This is definitely a bug , I’m a bit disappointed in the Corona team for repeatedly telling users to use the sample code. 

The very fact that “submitted” occurs twice, and “ended” occurs once, indicates that the listener isn’t installed twice, as in that case you would get an even number of both events.  

For me, it’s happening on a Samsung Galaxy Tab 4.

Much thanks to Robert Phillips who pointed out the problem only occurs when you choose something other than “done” for the return key value. 

I was using “go” and “search” for return key values – switching back to “done” resolved the issue. 

Hi @charles.l.capps,

Thanks for detailing this. Can you please file a bug report so we have it logged in our system? Please include a very basic sample project along with the bug report (you may be able to modify our “Interface>NativeKeyboard” sample for it).

When the bug is filed, please post back with the case # here for reference.

Thanks,

Brent

Sure, I’ll file a bug tonight when I’m not at work. 

I’ll create a minimal sample project that reproduces the issue. 

Sorry about my being a bit critical, I realize the sample code a user submitted doesn’t include the call to “myTextField:setReturnKey(‘go’)” which is needed for the bug to occur.

Thanks Charles, and we appreciate it. It’s fine to be “critical” about a legitimate bug. :slight_smile:

Brent

Okay, I submitted a bug including the minimal code needed to reproduce, and exact steps. 

FYI, this happens on my Galaxy S5 smartphone, as well as on my Galaxy Tab 4. 

It’s possible it affects all Android devices, or all Samsung devices, but I obviously can’t infer that without buying all the devices in the world  :slight_smile:

Thanks for looking into this – this bug is forcing me to use the “done” key on all of my native inputs. Which is a bit sad, since I’d like to use the search icon in a few places, and the “go” key in another place.

Cheers! 

You should have received an email that had a Case Number in it. Please post that case # here for reference.

Thanks

Rob

Charles,

I ran into this issue it appears in April and had to implement a boolean to work around the issue. You can do this dirty method, or hold off until the bug if fixed. I ended up getting too frustrated and decided to write my code in Java. Good luck! 

I do love the little amount of code required with Corona, but unless I’m making a game I probably will just write my code in native code. After I finish this social based app I plan on making a game  :wink:

Justin

Yes, I could have a boolean keeping track of whether a submission is in progress (in my case, doing an HTTP request, validating the response, then loading a new scene with composer or displaying an error message.) 

However, having this extra state is extra complexity, and this boolean must be reset to false after every possible way for the triggered code to succeed or fail (otherwise, the keyboard would stop working! ). 

TL; DR - I decided it’s best to just use the “done” return key rather than add new failure points and poor software engineering to my code just to work around the bug. 

So, I’ll be happy when it’s fixed. 

Makes sense. Just stating it CAN be done, but will be extremely ugly. I couldn’t imagine this bug being too difficult to resolve, but who knows.

Hi,

I was trying native keyboard last night and it I bumped into a problem. I have a username field and password field. After finishing typing in my username field, I press “next” and the cursor goes to the password field and then vanish straight away.

Here’s my code:

-- USERNAME -- local function onUser(e) if(e.phase == "began") then print("user = ", e.phase) elseif(e.phase == "editting") then print("user = ", e.phase) elseif(e.phase == "submitted" or e.phase == "ended") then print("user = ", e.phase) native.setKeyboardFocus(passBar) end end local userBar = native.newTextField(w/2, h/2-100, 300, 70) userBar.align = "left" userBar.hasBackground = false userBar.font = native.newFont("Arial", 30) userBar.isFontSizeScaled = true userBar.placeholder = "Username" userBar:setTextColor(255/255, 255/255, 255/255) userBar:setReturnKey("next") userBar:addEventListener("userInput", onUser) -- PASSWORD -- local function onPass(e) if(e.phase == "began") then print("pass = ", e.phase) elseif(e.pahse == "editting") then print("pass = ", e.phase) elseif(e.phase == "submitted" or e.phase == "ended") then print("pass = ", e.phase) native.setKeyboardFocus(nil) end end local passBar = native.newTextField(w/2, h/2+100, 300, 70) passBar.isSecure = true passBar.align = "left" passBar.hasBackground = false passBar.font = native.newFont("Arial", 30) passBar.isFontSizeScaled = true passBar.placeholder = "Password" passBar:setTextColor(255/255, 255/255, 255/255) passBar:setReturnKey("done") passBar:addEventListener("userInput", onPass)

From the logcat, when I pressed the username field, I get

user = began

but when I pressed “next”, I get

user = submitted

user = ended

pass = began

pass = ended

it seemed like I pressed the return button twice. How to fix it?

Thanks

Ming

What happens if you don’t set… :setReturnKey()?

Rob

Rob, it appears to have the same outcome…

Ming

Any solutions, Rob?

Thanks in advance.

Ming