substance
substance copied to clipboard
Key events don't work properly on Android Chrome (with default keyboard)
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?
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.
A long thread about the issue: https://bugs.chromium.org/p/chromium/issues/detail?id=118639
Does it ignore the key events because of this? https://github.com/substance/substance/blob/28a86924dda0ab1e060cc5111b24830e2ff20609/packages/surface/Surface.js#L254
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.
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
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.
@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.
I am pretty sure things are good here now. You may want to test it out.
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
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
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.
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
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
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
With my experience i would like to share my knowledge,
Desktop Browsers
<input type="number">
- Safari - allows Chars too (may be depends on version)
- maxlength not supported.
- Cursor position is unable to detect.
- @keypress event detected.
<input type="text">
- works as expected.
<input type="tel">
- works as expected.
Android Mobile Browser (Chrome)
<input type="number">
- Opens numeric keypad
- @keypress event detected.
- Cursor position is unable to detect.
<input type="text">
- @keypress event not even detected.
- maxlength not working properly.
<input type="tel">
- @keypress event is detected.
- maxlength supported.
- 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.
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