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.
Related
I am using Unity in my Android project. There are input fields in my app. As soon as I click on the field the keyboard pops up. I want the keyboard to only show up when there is a double-tap on the field. But I am not able to get it to work and I have tried several ways.
Requirement 1: Single tap shouldn't open keyboard
Requirement 2: Double tap should open keyboard
I tried OnPointerClick method of IPointerClickHandler but this doesn't seem to work. I used this code in one of the scripts attached to input field with IPointerClickHandler.
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.clickCount == 2)
{
Debug.Log("UNITY - Double click");
}
else if (eventData.clickCount == 1)
{
Debug.Log("UNITY - Single click");
}
}
Then there is also the question of how to hide the keyboard or prevent it from opening on single tap. This also I am not able to solve. I started with clicking the Hide Soft Keyboard in control setting of InputField in Unity editor. But surprisingly this starts opening a keyboard which has mobile input.
Can someone help? I have been stuck on this for some time I can't seem to be getting anywhere.
I am showing a simple HTML edit box inside an Android webview. User enters some input through the Android standard IME (or any soft IME to that matter) and presses ENTER key. Expectation is once user presses the ENTER key, the HTML page should be notified that it can post the data to the server.
Right now I am not able to tell this to the HTML page. So user has to click somewhere on the screen, upon which the POST happens.
My question is how can i notify the webview (finally the HTML page) to POST data to server on soft key ENTER press
There is a library called as Jockeyjs it can be used to communicate between native and the Webview.
you can get keypress event from native and pass it to webview. Or else if you can use jquery on your html you can do some thing like this
$( "#inputbox" ).on( "keypress", function( event ) {
if(event.which ==13) //13 is for enterkey
{
$("#form").submit();
}
});
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!');
}
});
The Issue:
Using
<input id="my_tel" type="tel" onkeypress="alert(event);"/>
<input id="my_num" type="number" onkeypress="alert(event);" />
The issue is that pressing done or enter or go key in android, nothing happens.For all other keys it works fine. When i tried to alert what event is being fired i found none.
The keypad does not hide (which is very sad) on pressing go/enter/done button.
However using
input type="text"
the issue does not exist.
Here is what i tried :
A. Used input type="text" and do not allow user to enter anything except
numbers.
Problem with this approach : The user is always presented with the default textual keyboard, and she/he has to switch, from default text to number pad,
which is not elegant and a turn off as i have many such pages in my project.
B. Used events like 'touchstart'and 'touchend' but no luck.
C. The input box is not even losing focus on key press so the solution
html phonegap android : numeric soft keyboard has next instead of go button is not useful.
Possible solution :
We can use the SoftKeyBoard plugin (https://github.com/phonegap/phonegap-plugins/tree/master/Android/SoftKeyboard). And hope that this problem is solved by this. But seriously can't there be a better solution??
Note : The problem is not observed in the iOS app,just android.
Another Note : No DOM event is fired even on pressing backspace key, but atleast the the backspace key is doing its job. In my case the done/go/enter key does not seem to execute its default behavior.
are you using iScroll?, if you are try removing it for a quick test and see what happens. I use it on a phonegap app and it's doing strange things with the inputs.
does anybody knows how to force keyboard open on android browser (4.0 - maybe less)?
i tried this solution and it does not worked for me.
in project i am trying to get a text input working, but after submitting (intercept by jQuery) it holds focus but the keyboard disappears.
snippets:
$('#typer').blur(function () {
$(this).focus().click();
});
$('#typer').bind('keyup', function (e) {
var input = $.trim($(this).val());
// some lines of code..
$(this).val('').focus(); // clean up
}
iOS is also interesting.. but not tested yet.
Android pulls up soft keyboard whenever text input field is in focus. "Go" or "Done" button on Android works as form submit, therefore input text looses focus and keyboard disappears. User expects the keyboard to disappear after "Go", "Done" or "Enter" is pressed - so Android follows this rule. Forcing re-focus on field's blur will not do much since technically you moved to a different window.
$('body').click(function() { $('#typer').focus(); }
can provide a partial solution, whereby user has to click once anywhere in the body of the page for the typer to re-gain focus. It causes OS to move back to browser Activity and focus the input field. This fiddle shows it as an example: http://jsfiddle.net/Exceeder/Z6SFH/ (use http://jsfiddle.net/Exceeder/Z6SFH/embedded/result/ on your Android device)
Other than writing a PhoneGap-like wrapper to control imeOptions of the keyboard, I am not aware of any solution that can solve this problem.