Can't dismiss the keyboard

I am able to bring up the native keyboard (iOS only tested so far), but I can’t dismiss it. I set the inputType to “number”, and I get the number keyboard with a blank spot in the lower left and the “delete” key in the lower right. There is no “done” or “submit” button. Tapping away from the keyboard doesn’t work either.

So how do you dismiss the keyboard?

[code]
local function fieldHandler( getObj )

– Use Lua closure in order to access the TextField object
return function( event )

print( "TextField Object is: " … tostring( getObj() ) )

if ( “began” == event.phase ) then
– This is the “keyboard has appeared” event

elseif ( “ended” == event.phase ) then
– This event is called when the user stops editing a field:
– for example, when they touch a different field or keyboard focus goes away

print( "Text entered = " … tostring( getObj().text ) ) – display the text entered

elseif ( “submitted” == event.phase ) then
– This event occurs when the user presses the “return” key
– (if available) on the onscreen keyboard

– Hide keyboard
native.setKeyboardFocus( nil )
end

end – “return function()”

end

local numberField = native.newTextField( 150, 130, 30, 30, fieldHandler( function() return numberField end ) )
numberField.inputType = “number”
[/code] [import]uid: 52127 topic_id: 15427 reply_id: 315427[/import]

Hey,

I had the same problem with you, in fact I can never get the phone to recognize submitted events. My fix, while not what I wanted, was to put native.setKeyboardFocus( nil ) under the ended statement.

If it helps I was testing how the keyboard worked in other apps (itc mobile for one) and none of them hide the keyboard if click anywhere else, only if you submit your text.

I guess it’s not just a Corona issue but an over all Apple one. [import]uid: 23649 topic_id: 15427 reply_id: 57041[/import]

Hey guys,

Try this code - just change “background” to whatever your background image is called;

[lua]local function hideKeyboard ()
native.setKeyboardFocus( nil )
end
background:addEventListener(“tap”, hideKeyboard)[/lua]

I also sell a template on the Techority Store (totally unrelated to Ansca) that uses the keyboard for a math game where the answer is typed in, submitted and checked, if that interests either of you.

Peach :slight_smile: [import]uid: 52491 topic_id: 15427 reply_id: 57084[/import]

Hey Peach,

Wow theres an idea that would have never occurred me to. I’d update my app with it but I submitted it to apple 3 days ago and don’t want to move back in the approval process. When I update it I’ll fix it.

Thanks. [import]uid: 23649 topic_id: 15427 reply_id: 57126[/import]

@Peach,
That may work to dismiss the keyboard by tapping the background, but why isn’t there a submit or done button on the numeric keyboard? [import]uid: 52127 topic_id: 15427 reply_id: 57135[/import]

I thought there was a return button on there?

In any case, you could make your own button next to the input field that submits; would that work? :slight_smile: [import]uid: 52491 topic_id: 15427 reply_id: 57236[/import]