I'm new to Android Phonegap. I'm using Phonegap cordova 3.3.0 to develop phonegap application. But I don't know how to trigger "enter" event on Android keyboard.
For example: when I touch on Input field, the keyboard appear, and I want to submit the form when press "Enter/go" button. Please tell me how to do it, or give me the reference link?
Thanks very much!
Try this
$(document).keypress(function(e) {
if(e.which == 13) {
alert('You pressed enter!');
}
});
Related
I use C++ Builder Tokyo 10.2.3 and trying to do something very simple on Android like typing some text into an Edit box.
If I press Next or Done key on virtual keyboard everything is fine.
If I press an Exit Button to go back the previous form it looks it is fine but then if I press Android Back button application crash.
It took me hours to identify the problem but couldn't find any solution but trying to disable all other objects when user clicks in an Edit box and enable them if user click on Next..
It seems to me a bug but need to make sure before report it to Embarcadero.
Thanks
I found the problem and a solution. In short, there is a bug in C++ Builder Tokyo 10.2.3 as if virtual keyboard on Android hide/close because of focus change on a form virtual keyboard doesn't take it as it is hidden properly.. FormVirtualKeyboardHidden working fine but I don't know somehow application crashes.
So, the solution is to using platform services. Just hide the keyboard manually on FormFocusChanged event.
void __fastcall TForm1::FormFocusChanged(TObject *Sender)
{
di_IFMXVirtualKeyboardService VirtualKeyboardService;
if(TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXVirtualKeyboardService), &VirtualKeyboardService))
{
VirtualKeyboardService->HideVirtualKeyboard();
}
}
When I write into a line edit using the Android keyboard, and I press the "Done" button (screenshot below), the keyboard does not disappear. This happens even in a newly created project with just a line edit (I tested it).
How can I make "Done" to hide the keyboard?
Please note that I am looking for a developer solution (i.e. programming, not user oriented) and a native way (i.e. C++/Qt, not Java).
I'm using Qt 5.2.0.
You have to call the QInputMethod::hide() slot.
C++ Solution
connect(ui->lineEdit, SIGNAL(editingFinished()), QGuiApplication::inputMethod(), SLOT(hide()));
QML Solution
TextInput {
Keys.onEnterPressed: {
//...
Qt.inputMethod.hide()
}
Keys.onReturnPressed: {
//...
Qt.inputMethod.hide()
}
}
We are running PhoneGap 2.6 on Android 3.22 (also jquery mobile and backbone are also in the mix). We want to make it so the user can tap the enter key to submit a form after entering a value in a field. The field is a numeric input.
<input id="myfield" type="number">
Unfortunately, the enter button on the soft keyboard appears to be disabled. So when you tap it, no event is fired. None of the following work:
$('#myfield').on('keyup', keyhandler);
$('#myfield').on('keydown', keyhandler);
$('#myfield').on('keypress', keyhandler);
$('#myfield').keyup(keyhandler);
$('#myfield').keydown(keyhandler);
$('#myfield').keypress(keyhandler);
keyhandler: function(e) {
console.log('You tapped a key');
if (e.keyCode == 13) {
console.log('You tapped ENTER! Yay!');
}
}
Is there a way to enable the enter button on a numeric keyboard?
Not sure if this relates to your problem... but you can simulate form submit similar to what happens when you click on 'Go' via a press via the 'Next' button on a numeric keyboard. You can detect the next keyboard press by using the following bind in JQuery:
$('input').on('keydown', function(e){
if(e.which === 9) {
//your code here
}
});
The 'next' button emulates the tab keypress event on a keyboard, which is key code 9. Unfortunately, keypress and keyup events do not detect the next key event, so you need to bind it on keydown.
I have a mobile app and I can't use JQuery Mobile at the moment, only JQuery.
I found out that in Android mobile the "onkeyup" event is not working at all, only if the user type "back" the event fires.
I have one "input" field (HTML5) and need to attach the onkeyup event to it. What to do? I tried to replace the val(), adding the val somhting like "#" and remove it quickly. It doesn't helped.
Any ideas?
You can use this below.
$(document).ready(function() {
$("#MyElement").keyup(Function(e) {
$("#MyElement").val("MyValue");
});
});
the e param should tell you what key was pressed with the properties keycode and which.
hope this lends you to the right direction.
I'm having some issues with the softkeyboard behaviour in flex 4.6 and air 3.1
I have a list with a search bar on top. When a user selects the TextInput component the softkeyboard pops up like it should.
Now when the user is done typing his text and presses the return (or the done/search/...) key I want the softkeyboard to disappear.
What I've tried so far:
I've set the returnKeyLabel property to "done" and the button shows
up accordingly. However it only dismisses the keyboard on Android, on
IOS the keyboard just stays up.
I then tried by not setting the returnKeyLabel and manually
catching the Return key and setting the focus to another element that
does not require a softkeyboard but that didn't work either.
I also tried by dispatching my own "faked" click events when the Return key was pressed but this also didn't work.
As part of searching about this problem I found this Dismiss SoftKeyboard in Flex Mobile but that didn't work either. Or at least not in flex 4.6
Now does anyone know of a good way to hide the softkeyboard or make the returnKeyLabel "done" work on IOS that will work with flex 4.6/air 3.1?
Have you tried something like this?
<s:TextInput prompt="First Name" returnKeyLabel="done" enter="handlerFunction()"/>
private function handlerFunction():void{
stage.focus = null
}
For flex mobile android apps I have mimicked the intuitive ios way of tapping on the background to remove the softkeyboard as follows:
import spark.components.supportClasses.*
protected function application1_clickHandler(event:MouseEvent):void
{
if(event.target is StyleableTextField || event.target is StyleableStageText){
// ignore because came from a textInput
}else{
stage.focus = null
// to remove the softkeyboard
}
}
<s:TextInput prompt="First Name" returnKeyLabel="done" enter="{stage.focus = null}"/>
This is the same as Francis' answer, but it saves having to make a new function