Jquery focus () not working in mobile (Android), phonegap-cordova
I am new to jquery, please help! it works great on the web but doesn't work on mobile.
$(document).on('click', 'label', function(){
if (!$(this).next('input').is(':checked')) {
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').textinput("enable");
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').slider("enable");
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').focus();
} else {
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').textinput("disable");
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').slider("disable");
}
});
+3
source to share
2 answers
I found a solution for this, I used "touchstart" instead of "click", it worked.
$(document).on('touchstart', 'label', function(){
if (!$(this).next('input').is(':checked')) {
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').textinput("enable");
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').slider("enable");
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').focus();
} else {
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').textinput("disable");
$('input[data-cat-qty="' + $(this).next('input').attr('data-cat') + '"]').slider("disable");
}
});
+3
source to share
I'm pretty sure iOS and Android don't allow starting focus
on login unless the user gets physical access.
I found this hack on GitHub , but it only targets Android and I don't know if it will work on iOS as well:
// From Lindsey Simon
/**
* This is a hack to make text input focus work in Android/PhoneGap
* where calling el.focus() doesn't actually have the blinking cursor
* effect = scumbag.
* @param {Zepto} $el A zepto element.
*/
ws.focus = function($el) {
var el = $el.get(0);
el.focus();
el.setSelectionRange && el.setSelectionRange(0, 0);
};
+1
source to share