Text Field Input?

Hello Everyone,

I’m new to Corona, and I’ve already run into a bit of a snag.
I know there are native text field objects which I need to use in order to get user input.
But is there any examples that do more than just place a text field on the screen?
I can’t seem to find any examples of actually getting input from the text field.
Also, I assume that since, there are only native text entry elements, this will be the only way to get user input, such as names? Like say, for a game where you can name your character?

Thanks for any assistance,
Dower [import]uid: 100618 topic_id: 20055 reply_id: 320055[/import]

Hey there, try something like this;

[lua]local function test (event)
if event.phase == “submitted” then
print (inputField.text)
end
end

inputField = native.newTextField( 20, 30, 280, 30, test)
inputField.font = native.newFont( native.systemFontBold, 18 )[/lua]

That’s plug and play so will run by itself.

It just prints the text the user entered when you hit enter but hopefully it gives you something to go on.

If you need more advice feel free to ask :slight_smile:

Peach [import]uid: 52491 topic_id: 20055 reply_id: 78322[/import]

Thanks Peach, that helped a lot!
The only thing I would add, is the following line into the if block:

 native.setKeyboardFocus( nil )  

I found that in anther post you replied to.

Thanks again! [import]uid: 100618 topic_id: 20055 reply_id: 78500[/import]

No worries - and yes, if you wish to hide the keyboard that’s very useful.

You can also use [lua]inputField.txt = “”[/lua] if you’d like to clear the text from the field once the user submits it. (In some games this makes sense, like word guessing games.)

Peach :slight_smile: [import]uid: 52491 topic_id: 20055 reply_id: 78637[/import]