How to scroll in to focused textbox in android + phonegap? - android

I am using PhoneGap (Cordovar 2.5) and jQuery Mobile 1.3.0. On iOS, whenever I focus on a text box, the keyboard shows and push up the page, but on Android it doesn't. I have tried to use android:windowSoftInputMode="" but no success. Please help.

In any part of you app (js file, of course) pus this script:
if(/Android 4\.[0-3]/.test(navigator.appVersion)){
window.addEventListener("resize", function(){
if(document.activeElement.tagName=="INPUT"){
window.setTimeout(function(){
document.activeElement.scrollIntoViewIfNeeded();
},0);
}
})
}
The answer was in: Android does not correctly scroll on input focus if not body element

Related

ionic keyboard focus on input box issue

I am using angular with ionic
I have used below code
<input type="number" name="foo" ng-model="field.field_value" class="form-number" ng-focus="keyboardFocus(this)" >
$scope.keyboardFocus=function(t){
var a= $(t).attr('class');
alert(a);
// $ionicScrollDelegate.scrollBottom();
// $ionicScrollDelegate.$getByHandle(t).scrollTop();
$("."+a).css('position','absolute');
$("."+a).css('top','0px');
}
But scroll is not working in current position on textbox. keyboard focus on textbox is not working but type any text foucus is working
Imho, no need to use $ionicScrollDelegate, change position, scroll manually or any other complicated stuff.
You just need the Ionic Keyboard Cordova plugin to be installed. See the explanation here.
To install it:
cordova plugin add com.ionic.keyboard
Nothing else to do. On focus, the page will move automatically.
Of course, it will work only on real devices, but in my experience, with this plugin, focused form elements are never hidden under the keyboard.
Best way will be to use $ionicScrollDelegate, for that you need to define delegate-handle value on element this way:
<input type="number" name="foo" ng-model="field.field_value" class="form-number" delegate-handle="myInput" ng-focus="keyboardFocus('myInput')" >
And then pass into keyboardFocus this way: ng-focus="keyboardFocus('myInput')" .
And function will become
$scope.keyboardFocus=function(handleValue){
$ionicScrollDelegate.$getByHandle(handleValue).scrollTop();
}

Input from hardware keyboard in Cordova (using Angular & Ionic)

I have some hardware sending input to my app, either by Bluetooth or wired hardware keyboard. At the moment I have a text field taking the input. I need the field to auto-focus when the screen loads, but without haivng the soft keyboard popup on focus.
I've tried autofocus attribute for HTML, but it messes with the view when I'm using Ionic.
I also tried using an angular directive, to focus after 500ms.
.directive('focus', function($timeout, $parse, $cordovaKeyboard) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$timeout(function() {
element[0].focus();
}, 500);
}
}
})
Is there a way of focusing without the soft keyboard displaying in both iOS and Android? I need the soft keyboard to popup only when the user clicks on the input field manually.
The other option would be to have a listener for any hardware keyboard inputs - but I can't see any way to do this in Cordova.
The solution for hide/show software keyboard in Ionic framework project is cordova-plugin-ionic-keyboard - see it on GitHub: https://github.com/ionic-team/cordova-plugin-ionic-keyboard
Short info is also in Ionic documentation: https://ionicframework.com/docs/native/keyboard
(Text was updated on 7th Jan 2020, because previously recommended extension ionic-plugin-keyboard is deprecated.)

function event.preventDefault() not working in android chrome

Here is a simple example of the issue I am facing: jsfiddle .
You can not enter values into the text field on PC. The very same code does not work on android chrome. I am able to type anything into the field.
I am trying to prevent text being entered into a text box under a certain condition
Here is the function
function func(event, src){
if (condition){
alert(33);
event.preventDefault();
}
}
I have used it like this:
<input onkeydown="func(event, $(this))" />
The code works perfectly on windows ie and chrome. However on chrome in android, it shows an the alert 33 but it does not prevent text from being entered. I have tried event.stopPropagation(); and return false but the output is still the same(only shows the alert).
Note: I can not use $("input").keydown() because of some other features. So I can only use events via html .
You can try this approach:
HTML
<input id="pVal" />
JavaScript:
const inpt = getElementById('pVal')
inpt.addEventListener('textInput', evt => {
evt.preventDefault();
})
It works in Android Chrome

Mobile Web - Disable long-touch/taphold text selection

I've seen/heard all about disabling text selection with the variations of user-select, but none of those are working for the problem I'm having. On Android (and I presume on iPhone), if you tap-and-hold on text, it highlights it and brings up little flags to drag and select text. I need to disable those (see image):
I've tried -webkit-touch-callout to no avail, and even tried things like $('body').on('select',function(e){e.preventDefault();return;}); to no avail. And the cheap tricks like ::selection:rgba(0,0,0,0); won't work either, as hiding these won't help - selection still happens and it disrupts the UI. Plus I'm guessing those flags would still be there.
Any thoughts would be great. Thanks!
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
-webkit-tap-highlight-color:rgba(0,0,0,0);
This will disable it for every browser going.
Reference:
jsFiddle Demo with Plugin
The above jsFiddle Demo I made uses a Plugin to allow you to prevent any block of text from being selected in Android or iOS devices (along with desktop browsers too).
It's easy to use and here is the sample markup once the jQuery plugin is installed.
Sample HTML:
<p class="notSelectable">This text is not selectable</p>
<p> This text is selectable</p>
Sample jQuery:
$(document).ready(function(){
$('.notSelectable').disableSelection();
});
Plugin code:
$.fn.extend({
disableSelection: function() {
this.each(function() {
this.onselectstart = function() {
return false;
};
this.unselectable = "on";
$(this).css('-moz-user-select', 'none');
$(this).css('-webkit-user-select', 'none');
});
return this;
}
});
Per your message comment: I still need to be able to trigger events (notably, touchstart, touchmove, and touchend) on the elements.
I would simply would use a wrapper that is not affected by this plugin, yet it's text-contents are protected using this plugin.
To allow interaction with a link in a block of text, you can use span tags for all but the link and add class name .notSelected for those span tags only, thus preserving selection and interaction of the anchors link.
Status Update: This updated jsFiddle confirms you concern that perhaps other functions may not work when text-selection is disabled. Shown in this updated jsFiddle is jQuery Click Event listener that will fire a Browser Alert for when the Bold Text is clicked on, even if that Bold Text is not text-selectable.
-webkit-user-select:none; wasn't supported on Android until 4.1 (sorry).

Titanium Appcelerator Android - Open default soft keyboard in number view

I have an address search field in my app. When this field gets focus I want to open the keyboard as in the following image.
It works fine for iOS when the keyboard type is set to Titanium.UI.KEYBOARD_NUMBERS_PUNCTUATION as in the following code
var search = Titanium.UI.createSearchBar({
barColor:'#c8c8c8',
autocorrect:true,
hintText:'enter address',
height:'43dp',
top:'75dp',
autocapitalization: Titanium.UI.TEXT_AUTOCAPITALIZATION_WORDS,
keyboardType:Titanium.UI.KEYBOARD_NUMBERS_PUNCTUATION
});
However on Android it appears as in the following image.
I am using Titanium mobile SDK 1.7.5
You should probably add :
softKeyboardOnFocus : Titanium.UI.Android.SOFT_KEYBOARD_SHOW_ON_FOCUS
Unfortunately, it may be overridden by the system. Try it on another Android system (3.0 for example) if the problem persist.

Categories

Resources