Hi,
I was wondering if there is a way to dismiss the keyboard with the click of the return key/done key on iOS and or Android when typing in a textBox. I have looked at the key events document and I cannot figure out how to do it.
Thanks.
Hi,
I was wondering if there is a way to dismiss the keyboard with the click of the return key/done key on iOS and or Android when typing in a textBox. I have looked at the key events document and I cannot figure out how to do it.
Thanks.
Hi,
You should implement a listener function for the textBox object.
This should do the trick for textBox -> https://docs.coronalabs.com/api/library/native/newTextBox.html
If you are using a text field, that’s the way(pretty much the same). https://docs.coronalabs.com/api/library/native/newTextField.html
Hi,
You should implement a listener function for the textBox object.
This should do the trick for textBox -> https://docs.coronalabs.com/api/library/native/newTextBox.html
If you are using a text field, that’s the way(pretty much the same). https://docs.coronalabs.com/api/library/native/newTextField.html
So I forgot to respond to this thread but my issue never got resolved. I set up in my code the functions from this link, https://docs.coronalabs.com/api/library/native/newTextBox.html, however whenever I click “Done” on my keyboard it just adds a new line rather than triggering the ended/submitted if statement. I have implemented the same functionality in my app using textFields and the if statement works with the click of the done button. I am not sure why textBoxes specifically are giving me a problem.
You should get an “ended” or “submitted” phase in which case you should call:
native.setKeyboardFocus( nil )
to hide the keyboard. You can also put a touch listener on the background that will also hide the keyboard using that statement.
Rob
I understand how to dismiss the keyboard, that is not the issue. Using a textField I am able to setKeyboardFocus to “done” and have in a function that if the done button is clicked, the keyboard is dismissed. This does not seem to work for me using a textBox. I am using a version of this function shown below:
local function textListener( event )
if ( event.phase == “began” ) then
– User begins editing “defaultBox”
elseif ( event.phase == “ended” or event.phase == “submitted” ) then
– Output resulting text from “defaultBox”
print( event.target.text )
elseif ( event.phase == “editing” ) then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
Hi @rdvitali98,
The issue is more around how the OS behaves. Multi-line text boxes don’t move to the next field upon click of “done” or “return”, because then the user wouldn’t be able to type more than one line. By design, they are intended to do a “line carriage return” when the key is pressed… the user is expected to click/tap on some other field when they’re done editing the multi-line one.
Hope this helps,
Brent
You may always create transparent background to receive touches outside the keyboard and dismiss the keyboard.
So I forgot to respond to this thread but my issue never got resolved. I set up in my code the functions from this link, https://docs.coronalabs.com/api/library/native/newTextBox.html, however whenever I click “Done” on my keyboard it just adds a new line rather than triggering the ended/submitted if statement. I have implemented the same functionality in my app using textFields and the if statement works with the click of the done button. I am not sure why textBoxes specifically are giving me a problem.
You should get an “ended” or “submitted” phase in which case you should call:
native.setKeyboardFocus( nil )
to hide the keyboard. You can also put a touch listener on the background that will also hide the keyboard using that statement.
Rob
I understand how to dismiss the keyboard, that is not the issue. Using a textField I am able to setKeyboardFocus to “done” and have in a function that if the done button is clicked, the keyboard is dismissed. This does not seem to work for me using a textBox. I am using a version of this function shown below:
local function textListener( event )
if ( event.phase == “began” ) then
– User begins editing “defaultBox”
elseif ( event.phase == “ended” or event.phase == “submitted” ) then
– Output resulting text from “defaultBox”
print( event.target.text )
elseif ( event.phase == “editing” ) then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
Hi @rdvitali98,
The issue is more around how the OS behaves. Multi-line text boxes don’t move to the next field upon click of “done” or “return”, because then the user wouldn’t be able to type more than one line. By design, they are intended to do a “line carriage return” when the key is pressed… the user is expected to click/tap on some other field when they’re done editing the multi-line one.
Hope this helps,
Brent
You may always create transparent background to receive touches outside the keyboard and dismiss the keyboard.