Is it possible to select all input text on iphone device when focus / click?
Typically for a browser environment one would use:
$('input').bind("click focus", function() {
$(this).select();
});
This works for desktop browsers but appears unresponsive for iphone and presumably other mobile devices.
Basically you have to REARRANGE the events focus, then click, then touchstart
$('#myID').on('focus click touchstart', function(e){
$(this).get(0).setSelectionRange(0,9999);
//$(this).css("color", "blue"); FUBAR
e.preventDefault();
});
Setting a (small) timeout works best for me:
The iOS keyboard seems to be called in a delegate or something, as it kept loosing my focus event to be able to select stuff. The select()
did not work for the same reason.
I fixed it this way:
function focusMe(vitem) {
window.setTimeout(function() {
vitem.setSelectionRange(0, 9999);
}, 10);
}
<input onfocus="focusMe(this)" />
$('input[type="text"]').on('focus',function(){
$(this).get(0).selectionStart=0;
$(this).get(0).selectionEnd=999;
})
I originally found this information here, and there are other things people have tried that have achieved the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With