Not able to use maxlength in Android JellyBean - android

I am facing an issue in Android which is like whenever I am using the maxlenth attribute on input e.g. ; After entering 20 characters on android tab, that page gets hang, I am unable to delete anything or add anything in any other input, other pages works fine but not this page where I entered the charcters upto max limit
I am using on KArbonn Smart Tab 8
Android JellyBean

It is a well known Android 4.1 issue.
Jelly Bean WebView not working well with HTML maxlength attribute for text box
http://code.google.com/p/android/issues/detail?id=35264
Unfortunately, no fix yet. You can follow the above stack-overflow post where they have a JS fix.

I have found the answer and it is working for me:
x$("#fieldWithMaxLength").on("keydown", function(e) {
if(e.keyCode != 8) {
maxlength = $(this).attr('maxlength');
if(this.value.length >= maxlength ) {
var curIndex = $(this).attr('tabindex');
$('[tabindex=' + curIndex + ']').focus();
return false;
}
}
});

Related

Cordova startWith Methode not working on old mobiles

I used the Methode startsWith, which is only working on Android 5 and above.
if(array[var].startsWith("code"))
Is there another easy way to do this, so that its also working on Android 4 ?
startsWith is not a cordova method, is a javascript method. It will deppend on the support of the webview
Here you can see browser support
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
Note that it says:
"Android" -> No support.
"Chrome for Android" -> 36
On Android 5 the webview is based on chromium and updatable, right now it uses the version 48, so it supports the startsWith
On the link you have a polyfill, so you can use it with previous versions
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}

Google Places Autocomplete plugin isnt working in Firefox android

We are using google's places-autocomplete plugin on our website.
Of late we have received several complaints from our website visitors that this plugin isn't working in the Android version of Firefox. It works fine in the desktop version of Firefox however.
The problem can be simply observed by
Going to the places-autocomplete example here
Trying to enter a zip code in the "Enter a location" search input
You will observe the following 2 issues -
Google Auto-complete should show suggestions as you start typing the
zip code. But it doesn't until one types a space or , after the 5 digit zip code.
When the suggestions do show up (after typing space or ,), you can't choose the first suggestion. As you tap on it, the cursor moves back to the search input. You can however choose the second or third suggestion correctly.
Problem #2 is extremely annoying and frustrating for the user. We've had received several complaints about this.
I have confirmed this on Firefox version 36.0.2 on a Samsung S4 running Android 4.4.2.
How can this be resolved?
A work around for the second issue is to give the first autocomplete suggestion a top margin so the user can click it. Its not pretty but its functional.
css
.FirefoxAndroid .pac-container .pac-item:first-child {
margin-top: 20px;
}
js
<script>
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var is_android = navigator.userAgent.toLowerCase().indexOf('android') > -1;
if(is_firefox && is_android){
$('html').addClass('FirefoxAndroid');
}
</script>
I encountered the same issue today - the website I am working on is working perfectly on every web browser, the auto-complete as well except on FF mobile.
After trying 3-4 solutions the one that worked for me was to declare the var place at the top of my code.
I have something like that
var autocomplete;
var place;
var input = document.getElementById('location');
var options = {
componentRestrictions: {'country':'be'},
types: ['(regions)'] // (cities)
};
autocomplete = new google.maps.places.Autocomplete(input,options);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
place = autocomplete.getPlace();
...
}
It was not working only on FF mobile because I wasn't declaring place at the top.
Maybe it will help someone in the future who knows

Android app not working in kitkat version but working in lesser versions

I have a sencha application which runs fine on Jellybean version. When I tried to run it in Kitkat version, soft keyboard hiding my textfield. To sort out that, I gave android:windowSoftInputMode= "stateVisible|adjustResize" in AndroidManifest file. Though it got sorted, that induced the following bug as shown in the screenshot. View cuts in to halves. Is there any solution for this? Would be really thankful if anybody can help me in that. Thanks!
We can resolve this bug using javascript, by getting the offset of the element through id and scroll it to that particular offset dynamically
var panelHeight = Ext.get('panelId').getHeight();
console.log('offset of panel height scrollToFocussedElement : '+panelHeight)
var offset = document.getElementById('elementId').offsetTop;
if (navigator.userAgent.toLowerCase().match('android')) {
offset = offset + panelHeight;
}
console.log('offset in scrollToFocussedElement : '+offset);
Ext.getCmp('viewId').getScrollable().getScroller().scrollTo(0, offset);

phonegap app with 'touchstart' still very slow

Im making an app in html5 and converting it to an apk with phonegap.
For now you only have to alternately push the left div and the right div.
and when you do it your score wil get higher.
The problem is when i press them very fast the score wont change. It will only change upto a certain speed wich is very slow.
leftt = left div, rightt is right div
code:
// JavaScript Document
window.onload = function ()
{
var left= 0;
var right= 1;
var score =0;
var el = document.getElementById("leftt");
var el2 = document.getElementById("rightt");
el.addEventListener("touchstart", function(e) {
if(right ==1)
{
left=1;
right=0;
score++;
document.getElementById("score").innerHTML= score;
}
});
el2.addEventListener("touchstart", function(e) {
if(left ==1)
{
left=0;
right=1;
score++;
document.getElementById("score").innerHTML= score;
}
});
}
You should add the 'user-scalable=no' parameter to your viewport.
This will remove the 300ms delay that some browsers will add to your web application to account to double clicks (The fastclick library will actually turn itself off if it detects this scenario- https://github.com/ftlabs/fastclick).
There is a lot more in depth on this topic on HTML5Rocks - http://updates.html5rocks.com/2013/12/300ms-tap-delay-gone-away
While this article is applicable to Chrome for Android, the user-scalable=no trick has been in Chrome for some time and is in the Android WebView in KitKat.
There is a bug with Android version 4.0.4+ .Try turning off hardware acceleration for your webview with this line of code in your app java file:
super.appView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
This may be fixed as of 4.4 (KitKat uses Chromeview rather than webview).

masked input not working in android mobiles?

I am using the digitalbush masked input jQuery plugin. It is working fine in web browsers and the iPhone browser perfectly, but it is not working for Android mobile devices.
My issue :
mask is
in input field _ - _ - ___.
When I type numbers it will 12345685555___--
Example: http://rossbender.com/temp/mask.html
Any suggestions? How can I solve this?
Thanks
Prasad.
I resolved this issue with three actions, which have fixed this for all Android 4.0+ phones:
Update masked-input to at least version 1.4
Add type="tel" to the input, to trigger the numeric keyboard
Remove the input's maxlength attribute or set it to a value certain not to interfere with the caret action, like 20.
I tried using the raw script that Jonathan Rowny mentioned, but I was still having the same problem on an S3 - Chrome browser. I think it has something to do with inputs type="tel" and/or type="number". I ended up having to use another plugin. http://igorescobar.github.io/jQuery-Mask-Plugin/
jquery-mask (not to be confused with jquery-masked-input) is very similar but the syntax was slightly different. Hope this helps anyone else with this issue.
jquery-masked-input syntax:
$("#phone").mask("(999) 999-9999");
VS
jquery-mask syntax: ('#phone').mask('(000) 000-0000');
This was fixed awhile ago but for some reason the distribution posted on the website never took the changes. If you grab from the raw source, the fix works: https://raw.githubusercontent.com/digitalBush/jquery.maskedinput/master/src/jquery.maskedinput.js
After trying different mask libraries (Inputmask, ui-mask, ngMask) I ended up using jQuery-Mask-Plugin https://igorescobar.github.io/jQuery-Mask-Plugin/ which works pretty well and is also lightweight and well documented and has angularjs, react ,... samples.
I just ran into this problem and resolved it by removing the attribute type="number" from the asp textbox. After that masked input worked even on mobile devices.
The library used in the question is no longer being maintained. I switched my application to jQuery Mask Input as it works great, has a very similar base init call to the former library making for an extremely easy transition and, at the time of this post, jQuery Mask Input is regularly maintained at GitHub.
My issue was with the phone number masker moving the cursor back to the second position when 3 or 4 digits were entered. The cursor continued to act odd after that point. The problem was noticed using jQuery Masked Input v1.4.1 (old library) in android tablets using Chrome post major version 51.
To further enhance the accepted answer of Tony Brasunas, add following snippet in jquery.maskedinput.js for point number 3 to dynamically increase maxlength so it doesn't interfere with caret action.
Remove the input's maxlength attribute or set it to a value certain not to interfere with the caret action, like 20.
defs = $.mask.definitions;
tests = [];
partialPosition = len = mask.length;
firstNonMaskPos = null;
//insert snippet below
if (chrome && android) {
console.log("chrome && android");
var allAllowedRegExps = '';
jQuery.each(defs, function (key, value) {
allAllowedRegExps = allAllowedRegExps + key;
});
allAllowedRegExps = allAllowedRegExps.replace(/\[/g, '');
allAllowedRegExps = allAllowedRegExps.replace(/\]/g, '');
allAllowedRegExps = '[^' + allAllowedRegExps + ']';
var re = new RegExp(allAllowedRegExps, "g");
var actual = mask;
var replacedVal = actual.replace(re, "");
var actualValue = actual.length - replacedVal.length;
if ($(this).attr('maxlength') !== undefined) {
$(this).attr('maxlength', parseInt(this.attr('maxlength')) + parseInt(actualValue));
}
}
mask = String(mask);
This can be a quick fix:
var ua = navigator.userAgent;
var isAndroid = /Android/i.test(ua);
var isChrome = /Chrome/i.test(ua);
// Fix masking on Chrome for mobile devices
if (isAndroid && isChrome) {
$('.price_input').attr('type','tel');
}
It worked for me by using 1.4.1 and setting the max length to one plus the number of chars in the mask. The mask limited the actual input and the max length +1 fixed the problem of not being able to type numbers in the field.

Categories

Resources