trouble setting up login form on device

I’m having trouble getting the “next” key on the iPhone keyboard to advance to the next form field in a user login form, from email input box to password input box. The documentation notes to use native.setKeyboardFocus() to tell set the next input box by name rather than  relying on the “next” in iOS.

However, doing this…setReturnKey(playerPasswordInput) causes the app to crash on device when the scene loads.

Is the issue that playerPasswordInput isn’t declared until after native.setKeyboardFocus() or is there a better way to handle text input form boxes?

scene.buildAccountForm = function(event) playerEmailInput = native.newTextField(260, 135, 200, 22) playerEmailInput:addEventListener("userInput", textListener) playerEmailInput:setTextColor(.7, .7, .7) playerEmailInput.maxLength = 100 playerEmailInput.defaultText = "example@example.com" playerEmailInput.isFontSizeScaled = true playerEmailInput.size = 16 playerEmailInput.align = "left" playerEmailInput.text = "example@example.com" playerEmailInput.hasBackground = true playerEmailInput:setReturnKey(playerPasswordInput) -- instead of ("next") playerEmailInput.isValid = false scene.loginGroup:insert(playerEmailInput) playerPasswordInput = native.newTextField(260, 170, 200, 22)

So declaring the password field above the setKeyboardFocus did solve the crash, but the “next” key on the device still does not advance the focus to the password input field. 

setReturnKey() cannot accept a text field as it’s value. It’s a string. 

The next button won’t be able to do what you require on iOS (as per the docs). 

There are a few options you can do here… 

  1. In the text field listener, when the user has hit the done key, you can call setFocus to change to the next input field. Using the “submitted” or “ended” event: https://docs.coronalabs.com/daily/api/event/userInput/phase.html

  2. Add a “next/done” button on the screen or above the keyboard.

You can also check what event phase is returned when you use the “next” key on iOS. I haven’t tried this personally, but if it returns a “next”, “ended” or “submitted” event, you can do what I said in #1 also, but using the “next” key, rather than a “done” button.

Personally, I’d go with #1

Thanks, Danny. Using method #1, I got it to work with 

native.setKeyboardFocus(event.target.next) in the listener function

where event.target.next has been set to playerPasswordInput (the next field) in the form definition code.

So declaring the password field above the setKeyboardFocus did solve the crash, but the “next” key on the device still does not advance the focus to the password input field. 

setReturnKey() cannot accept a text field as it’s value. It’s a string. 

The next button won’t be able to do what you require on iOS (as per the docs). 

There are a few options you can do here… 

  1. In the text field listener, when the user has hit the done key, you can call setFocus to change to the next input field. Using the “submitted” or “ended” event: https://docs.coronalabs.com/daily/api/event/userInput/phase.html

  2. Add a “next/done” button on the screen or above the keyboard.

You can also check what event phase is returned when you use the “next” key on iOS. I haven’t tried this personally, but if it returns a “next”, “ended” or “submitted” event, you can do what I said in #1 also, but using the “next” key, rather than a “done” button.

Personally, I’d go with #1

Thanks, Danny. Using method #1, I got it to work with 

native.setKeyboardFocus(event.target.next) in the listener function

where event.target.next has been set to playerPasswordInput (the next field) in the form definition code.