There are multiple questions with answers related to my problem but unfortunately, none worked for me.
I have to detect the enter pressed on android keyboard and change focus from current matInput to next matInput.
I have tried keyup.enter, keydown and keypress but none worked for me. I implemented directive approach but doesn't trigger method when I am debugging app on Android device. Although, it does trigger the method on browser.
Here is what I am using.
HTML:
<mat-form-field class="ib-input-container-width">
<input matInput data-dependency="lastName" (keypress)="onChange($event.keyCode)" (keyup.enter)="handleNext('lastName')" [formControl]="form.get('FirstName')" type="text" >
</mat-form-field>
<mat-form-field class="ib-input-container-width" >
<input #lastName id="lastName" matInput [formControl]="form.get('LastName')" type="text">
TS:
handleNext(elementId){
let nextElement = document.getElementById(elementId);
console.log(nextElement);
nextElement.focus();
}
onChange(event){
console.log(event.keycode);
}
PS: I am on a working progressive web app using Cordova.
Update
I have tried solution from https://stackoverflow.com/a/28103608/3081929
But ng-change doesn't work either.
the code looks correct,
before running your codova app on android make sure you have compiled the angular project using angular cli and output should be set to www folder
I would like to make a Android function that would analyze the web content and automatically click the submit button and reload the page for updating. I have already get the on the webview and find the line of button. BUT I do not know what to do next. Anyone got ideas?
Try this by adding button with js to your html file:
<button onclick="myFunction()">Reload page</button>
<script>
function myFunction() {
location.reload();
}
</script>
Is it useful for you?You can use this to check checkbox, input value,... whatever with your webview?
http://executeautomation.com/blog/hybridapplication-robotium/
I'm writing an app with Phonegap and I have a register form that is sent through ajax. It works fine when you hit the register button and execute the formcheck() function. However, when I hit the GO button from my android phone it submits the form instead of going through the formcheck() process. I tried:
<form id="RegForm" onsubmit="formcheck();return false;">
My form has no proper submit button but a button like this:
<input type="button" id="submitbtn" onclick="formcheck()"/>
I also tried to create a new OnSubmitForm() function that calls the formcheck() one but with no avail. Thank you for helping.
Found it!
1) Add this to the JS section:
$(document).ready(function() {
$("#YourFormName").submit(function() {
FormCheck();
return false;
});
});
function FormCheck() {
... validation process here ...
}
2) Make sure to include a Submit button in your form .. ( <input type="submit" )
Hope it'll help others so my 5 hour trying & testing time won't go wasted :)
Simply ensure your form tag is:
<form type='submit' onsubmit='return false;'></form>
This makes the submit action not do anything.
If you also need to hide the keyboard refer to How can I hide the Android keyboard using JavaScript?. A simple onsubmit='hideKeyboard(); return false;' will take care of this.
I've got a search bar in a jQM/phonegap/cordova Android app.
How on earth do I detect when the user presses 'enter' or 'done' or whatever, so I can submit the search??
Do I have to build a custom key detector, or is there an event for this?
So frustrating - I can't find this in the docs anywhere....
Cheers all!
You would wrap the field in a form element ie:
<form id="foo">
<input type="text" />
</form>
Then to trigger an event when "the user presses the equivalent of 'return' on a PC keyboard i.e. 'go' or 'done', or whatever the OS has called it" you can use
$('#foo').submit(function(){
//do stuff
})
You would use the same code you would in a "normal" HTML application. Since you are using jQuery Mobile, you can use jQuery. If the field had an id of foo, you could use
$("#foo").on("click", function() {
//do stuff here
});
I have an Android 3.0 App with a WebView inside. The webview opens an website which uses java script. Opening the Website works fine. But whenever I click on a TextField, the keyboard doesn't appear.
I've already tried:
Tapping form field in WebView does not show soft keyboard
but no success. The keyboard seems to appear very shortly and thereafter disappears.
From my point of view this is caused by some javascript. This is the html of one of the input fields:
<input id="ToolbarOkCode" class="urEdf2TxtEnbl" type="Text" style="text-align:;width:150px;" value="" name="ToolbarOkCode" lsevents="{'Change':[{'ClientAction':'none'},{'type':'TOOLBARINPUTFIELD'}],'Enter':[{'ClientAction':'submit','PrepareScript':'return its.XControlSubmit();','ResponseData':'delta','TransportMethod':'partial'},{'type':'TOOLBARINPUTFIELD','~XRequest':'X'}]}" lsdata="{0:'',1:'',2:'',3:20,4:200,5:false,6:false,7:true,8:false,9:false,10:'STRING',11:'F4LOOKUP',12:'150px',13:'LEFT',14:false,15:'',16:false,17:false,18:false,19:'AUTO',20:true,21:'NONE',22:'MM/dd/yyyy',23:false,24:'',25:'',26:false,27:false,28:'',29:'NORMAL',30:1,31:false,32:0,33:0}" ct="I" autocomplete="off" ti="0" tabindex="0" maxlength="200">
I found the solution for my problem, It's pretty specific though, I hope it will help someone sometime...
I extendedWebViewClient, and overrode few of its functions.
my issue started when I loaded a propitiatory javascript: on onLoadResource(). For some reason, doing so caused the whole keyboard abnormality. I moved the script to run on onPageFinished() and the WebView acts normally again.
I have used your code and then try to run on android 2.2.It work fine and showing keyboard to enter value.I posting complete code that i run
String str="<input id=\"ToolbarOkCode\" class=\"urEdf2TxtEnbl\" type=\"Text\" style=\"text-align:;width:150px;\" value=\"d\" " +
" name=\"ToolbarOkCode\" lsevents=\"{'Change':[{'ClientAction':'none'},{'type':'TOOLBARINPUTFIELD'}],"+
"'Enter':[{'ClientAction':'submit','PrepareScript':'return its.XControlSubmit();','ResponseData':'delta','TransportMethod':'partial'},"+
"{'type':'TOOLBARINPUTFIELD','~XRequest':'X'}]}\" lsdata=\"{0:'',1:'',2:'',3:20,4:200,5:false,6:false,7:true,8:false,9:false,10:'STRING',11:"+
"F4LOOKUP',12:'150px',13:'LEFT',"+
"14:false,15:'',16:false,17:false,18:false,19:'AUTO',20:true,21:'NONE',22:'MM/dd/yyyy',23:false,24:'',25:'',26:false,27:false,28:'',"+
"29:'NORMAL',30:1,31:false,32:0,33:0}\"" +
"ct=\"I\" autocomplete=\"off\" ti=\"0\" tabindex=\"0\" maxlength=\"200\">";
WebView webView=new WebView(this);
webView.setFocusableInTouchMode(true);
webView.loadData(str, "Text/html","utf-8");
setContentView(webView);
Hope this will help you :)