Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keyPress event not firing in Android mobile

I am using backbone,marionette for my Application.I used same code for both desktop and mobile but keypress not working in mobile.I made a Jsfiddle for testing.

If you open this link in mobile event not firing,If you open in desktop it's firing.How can I resolve this.

can anyone help me.

Thanks.

like image 273
user3279058 Avatar asked Mar 18 '14 08:03

user3279058


2 Answers

Chrome mobile doesn't support keypress events properly for now. There is a long standing bug for this:

https://code.google.com/p/chromium/issues/detail?id=118639

I believe it should be fixed in v38. The bug report was closed as "won't fix".

like image 136
Quin Avatar answered Sep 17 '22 11:09

Quin


I will suggest two events on input box.

This will work on desktop webbrowser.

1) onkeypress = return isNumberKey(event);

function isNumberKey(e)
{
    var evt = e || window.event;

    if(evt) 
    { 
        var charCode = evt.keyCode || evt.which; 
    }
    else 
    { 
        return true; 
    }

    if((charCode > 47 &&  charCode < 58) || charCode == 9 || charCode == 8 || charCode ==46 || charCode ==37 || charCode==39)
    { 
        return true; 
    }

    return false;
}

This will work for mobile

2) onkeyup="numberMobile(event);"

function numberMobile(e){
    e.target.value = e.target.value.replace(/[^\d]/g,'');
    return false;
}

Apply both event on the input box and it will work.Only drawback is,It make it slow.But for now we have to live with it.

There is one issue woth this solution.Left navigation is not working.I will update more appropriate solution soon.

like image 29
Innovation Avatar answered Sep 19 '22 11:09

Innovation