substance icon indicating copy to clipboard operation
substance copied to clipboard

Key events don't work properly on Android Chrome (with default keyboard)

Open rquast opened this issue 8 years ago • 16 comments

I've been trying substance (latest dev), and noticed that the key events or something aren't properly firing on android chrome, which causes quite a few bugs (like not activating the check/save button, or delete key not working, etc).

Is there anything I could do to help with that?

rquast avatar Feb 20 '17 22:02 rquast

Chrome returns 229 as the keyup value for everything. Tested on android 5.1.1 phone and android 6 phone, latest chrome browser.

https://jsfiddle.net/milanraval/eu8tw2wk/

Screenshot is mac on left, android 6 phone on right.

chrome_browser

rquast avatar Feb 21 '17 01:02 rquast

A long thread about the issue: https://bugs.chromium.org/p/chromium/issues/detail?id=118639

rquast avatar Feb 21 '17 01:02 rquast

Does it ignore the key events because of this? https://github.com/substance/substance/blob/28a86924dda0ab1e060cc5111b24830e2ff20609/packages/surface/Surface.js#L254

rquast avatar Feb 21 '17 01:02 rquast

I read some of the comments in that long thread.. installing hacker's keyboard will fix the issue (sends correct key codes) with the typing and the save button getting triggered properly.

https://play.google.com/store/apps/details?id=org.pocketworkstation.pckeyboard&hl=en

So it appears to be an issue dealing with the returned key codes.

rquast avatar Feb 21 '17 01:02 rquast

Actually.. using hackers keyboard makes everything work as well as it does on desktop.

Something like this library may help augment the problem (or some kind of input event abstraction?): https://github.com/liftoff/HumanInput

rquast avatar Feb 21 '17 01:02 rquast

Hey @rquast,

Thanks for collecting this information. The tenor in the thread seems to be either using physical keyboards or not relying on keyboard events at all when it comes to mobile devices. For the latter, we need to do a dedicated development iteration with those devices, which we haven't done yet. Then we probably will go there: https://github.com/substance/substance/blob/28a86924dda0ab1e060cc5111b24830e2ff20609/packages/surface/Surface.js#L104-L132, add some platform detection and register adequate handlers.

Mobile devices is on our agenda, but we won't be able to address the next 3 months.

obuchtala avatar Feb 21 '17 08:02 obuchtala

@oliver---- yes, good idea. Someone else may do some more work on this or come up with a good solution. The thread didn't seem to have any great solutions from what I could read.

rquast avatar Feb 21 '17 08:02 rquast

I am pretty sure things are good here now. You may want to test it out.

rquast avatar Dec 10 '17 22:12 rquast

I faced the same issue, my solution is $('.NumOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9]/g, ''); });

$('.NumDotOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9.]/g, ''); });

$(".AlphaDotOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z .]/g, ''); });

$(".AlphaOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z]/g, ''); });

Reference: https://stackoverflow.com/a/19111723/4425004

Praneshjs avatar Feb 23 '19 11:02 Praneshjs

I faced the same issue, my solution is $('.NumOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9]/g, ''); });

$('.NumDotOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9.]/g, ''); });

$(".AlphaDotOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z .]/g, ''); });

$(".AlphaOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z]/g, ''); });

Reference: https://stackoverflow.com/a/19111723/4425004

working, thanks

shilpapatel-bcs avatar Apr 26 '19 06:04 shilpapatel-bcs

I faced the same issue, my solution is $('.NumOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9]/g, ''); });

$('.NumDotOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9.]/g, ''); });

$(".AlphaDotOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z .]/g, ''); });

$(".AlphaOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z]/g, ''); });

Reference: https://stackoverflow.com/a/19111723/4425004

Url for the stackoverflow link is missing btw, it's just (url) in markdown.

sevillaarvin avatar Nov 25 '19 14:11 sevillaarvin

There are heated discussions in Chromium about this issue since 2012. So far, no solution.

https://bugs.chromium.org/p/chromium/issues/detail?id=118639

cbdeveloper avatar Apr 16 '20 17:04 cbdeveloper

URL for stackoverflow could be Source Ans: https://stackoverflow.com/a/19111723/4425004 in previous post reference link is pointing to https://github.com/substance/substance/issues/url which caused the issue in loading.

My QA for the Issue https://stackoverflow.com/q/54866373/4425004

Praneshjs avatar Apr 17 '20 05:04 Praneshjs

I faced the same issue, my solution is $('.NumOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9]/g, ''); });

$('.NumDotOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9.]/g, ''); });

$(".AlphaDotOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z .]/g, ''); });

$(".AlphaOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z]/g, ''); });

Reference: https://stackoverflow.com/a/19111723/4425004

@Praneshjs It's working. Thank you so much

saikumar-carbanio avatar May 01 '20 15:05 saikumar-carbanio

With my experience i would like to share my knowledge,

Desktop Browsers

<input type="number">
  1. Safari - allows Chars too (may be depends on version)
  2. maxlength not supported.
  3. Cursor position is unable to detect.
  4. @keypress event detected.

<input type="text">
  1. works as expected.

<input type="tel">
  1. works as expected.

Android Mobile Browser (Chrome)

<input type="number">
  1. Opens numeric keypad
  2. @keypress event detected.
  3. Cursor position is unable to detect.

 <input type="text">
  1. @keypress event not even detected.
  2. maxlength not working properly.

 <input type="tel">
  1. @keypress event is detected.
  2. maxlength supported.
  3. Cursor position in input field can be detected.

Note: For detecting cursor position I used,

let caretPos = e.target.selectionStart

Let me know is there are any ways to detect cursor position in input[type="number"].


Suggestion

For Desktop browsers, use input[type="text"] to handle cases like keypress event and replace some values using cursor position.

For Android browsers, use input[type="tel"] to handle same cases mentioned above.

vaasav-kumar avatar Jul 09 '20 08:07 vaasav-kumar

I faced the same issue, my solution is $('.NumOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9]/g, ''); });

$('.NumDotOnly').on('input', function (event) { this.value = this.value.replace(/[^0-9.]/g, ''); });

$(".AlphaDotOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z .]/g, ''); });

$(".AlphaOnly").on("input", function (event) { this.value = this.value.replace(/[^a-zA-Z]/g, ''); });

Reference: https://stackoverflow.com/a/19111723/4425004

Thank you very much, this has been very helpful

YamidDev avatar Jan 12 '21 19:01 YamidDev