Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setSelectionRange for number input #3032

Closed
pizzarob opened this issue Sep 11, 2017 · 9 comments
Closed

setSelectionRange for number input #3032

pizzarob opened this issue Sep 11, 2017 · 9 comments

Comments

@pizzarob
Copy link

In order to provide a cross platform solution to auto-format telephone numbers while providing the best user experience on mobile devices one would need to be able to manipulate the selection range for number inputs. Since this is currently not possible we must provide users with a sub-par experience.

@annevk
Copy link
Member

annevk commented Sep 12, 2017

If you want this to be considered you'll need to address the points made in https://www.w3.org/Bugs/Public/show_bug.cgi?id=24796#c49 (it might also not hurt reading that bug through to get a sense of the problem space).

@domenic
Copy link
Member

domenic commented Sep 12, 2017

Also, you're explicitly not supposed to use type=number for telephone numbers...

Given that misconception, I think it's best we close this, since we don't have any use case presented. Happy to continue discussing in the closed thread though, and reopen if a use case is presented that shows evidence of addressing the linked bug's concerns.

@domenic domenic closed this as completed Sep 12, 2017
@charlieschwabacher
Copy link

I think it makes sense to re-open this - setting aside telephone numbers, there are many types of sectioned number inputs where it can make sense to examine selection.. for example social security number, credit card number, serial numbers, etc..

Its a common use case to implement these as multiple inputs for visual effect, and then to control selection w/ javascript so that as a user types it moves between the inputs naturally. Its important to use a number input so that mobile browsers use the appropriate keyboard, but the lack of control over selection range prevents doing things like moving selection to the input for the previous group of numbers when the left arrow or delete key is pressed with the cursor at the beginning of an input.

@domenic
Copy link
Member

domenic commented Sep 13, 2017

All of those are not appropriate for input type=number. Please read the spec for input type=number!!

@charlieschwabacher
Copy link

charlieschwabacher commented Sep 13, 2017

There is no practical alternative to input type number in iOS safari and android chrome that will bring up the appropriate keyboard. Specifying which keyboard should be used by mobile browsers is by far the most important practical use of input types.

I see in the spec the note that 'The type=number state is not appropriate for input that happens to only consist of numbers but isn’t strictly speaking a number.', but number inputs are widely used for credit card numbers (by stripe, amazon, etc..) because of the lack of alternatives.

@domenic
Copy link
Member

domenic commented Sep 13, 2017

OK, so it sounds like you should file a bug with Safari and Chrome then! (But, I am pretty sure the pattern="" attribute does what you want; see e.g. https://stackoverflow.com/a/6512618/3191 and various other Google results. If it doesn't, then file the bugs!)

@charlieschwabacher
Copy link

Wow - I did not know that worked! that does satisfy my use case, thank you.

@annevk
Copy link
Member

annevk commented Sep 14, 2017

<input inputmode=numeric> doesn't work? (That would be the proper way.)

@pizzarob
Copy link
Author

@annevk unfortunately no and I agree that would be the proper way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants