window.getSelection() fails when text selected in a form field
Categories
(Core :: DOM: Selection, defect, P3)
Tracking
()
Webcompat Priority | P3 |
People
(Reporter: bugzilla, Unassigned, NeedInfo)
References
(Depends on 1 open bug)
Details
Attachments
(3 files)
Reporter | ||
Comment 1•23 years ago
|
||
Comment 2•23 years ago
|
||
Comment 4•23 years ago
|
||
Comment 5•23 years ago
|
||
Comment 6•23 years ago
|
||
Reporter | ||
Comment 7•23 years ago
|
||
Comment 8•23 years ago
|
||
Comment 9•23 years ago
|
||
Comment 10•23 years ago
|
||
Comment 11•22 years ago
|
||
Comment 12•22 years ago
|
||
Comment 13•22 years ago
|
||
Comment 14•22 years ago
|
||
Comment 15•22 years ago
|
||
Comment 16•22 years ago
|
||
Comment 18•21 years ago
|
||
Comment 19•20 years ago
|
||
Comment 20•20 years ago
|
||
Comment 21•19 years ago
|
||
Updated•19 years ago
|
Comment 22•19 years ago
|
||
Comment 23•17 years ago
|
||
Updated•16 years ago
|
Comment 24•11 years ago
|
||
Comment 25•10 years ago
|
||
Comment 26•10 years ago
|
||
Comment 27•10 years ago
|
||
Comment 28•10 years ago
|
||
Comment 29•10 years ago
|
||
Comment 30•9 years ago
|
||
Comment 31•9 years ago
|
||
Comment 32•9 years ago
|
||
Comment 33•8 years ago
|
||
Comment 34•6 years ago
|
||
Comment 35•6 years ago
|
||
Updated•6 years ago
|
Updated•4 years ago
|
Comment 36•3 years ago
|
||
I have a function that checks on key press if pressing the key would cause the number input to go beyond maximum length specified. Because Firefox fails to return value on window.getSelection() in this case, the function thinks no text is selected, so if the input has already a value as long as maxLength, it will cancel user's input.
I have literally no way of working around this on Firefox while keeping this as a requirement.
See https://github.com/wojtekmaj/react-time-picker/issues/92
Comment 37•3 years ago
|
||
(In reply to Wojciech Maj from comment #36)
I have a function that checks on key press if pressing the key would cause the number input to go beyond maximum length specified. Because Firefox fails to return value on window.getSelection() in this case, the function thinks no text is selected, so if the input has already a value as long as maxLength, it will cancel user's input.
I have literally no way of working around this on Firefox while keeping this as a requirement.
See https://github.com/wojtekmaj/react-time-picker/issues/92
This looks like the same issue I reported here https://bugzilla.mozilla.org/show_bug.cgi?id=1527627, I have a workaround as:
document.activeElement.value.substring(
document.activeElement.selectionStart,
document.activeElement.selectionEnd
)
Comment 38•3 years ago
|
||
@daniel.lee1ibm, thanks. I have fight with this bug for 2 hours, till I understand that user use FF... and it simply do not pass any data in getSelection()...
BTW proper description under getSelection() page is only partially solution, cause every user expect that every browser behave exactly the same. So getSelection() should work in input fields, and laterrrr user can find out on https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection that there is more suitable command for it cause of... and then decide who is right... and how it should look/work.
TLDR I doesn't matter (at start) that chrome is wrong with getSelection(), it should work in FF.
Updated•2 years ago
|
Updated•2 years ago
|
Comment hidden (offtopic) |
Updated•2 years ago
|
Updated•2 years ago
|
Comment 42•2 years ago
|
||
Just a summary, this is an undefined thing in the spec, so browsers behave differently.
To properly fix this, we need to resolve https://github.com/w3c/selection-api/issues/83 which clarifies the Selection API behaviour when user selects contents inside a <input> or <textarea>. And https://github.com/w3c/selection-api/issues/7 which clarifies the Selection.toString()
API.
Description
•