javascript - How to inform the mobile keyboard about the desired input for a html input control? - Stack Overflow

Is there a way to inform the mobile keyboard on a mobile device that the possible values for an HTML in

Is there a way to inform the mobile keyboard on a mobile device that the possible values for an HTML input field are a subset of the possible values?

I try to express myself better with an example.

Let's say i have a username input text:

<input type="text" id="username">

when trying to type with a mobile device the mobile keyboard will do three non desired things:

  1. it tries to make me start typing a capital letter as the first char
  2. it adds a space after a "."
  3. it tries to make me start typing a capital letter after a '.'

So if I want to type j.doe (an example of a typical username)

and I type (one at a time): j . d o e I obtain J. Doe

I could, being an advanced mobile keyboard user, try to obtain the desired results by doing (for example on Swiftkey that has navigation arrows):

  1. press caps lock twice (so the first letter capital constraint is bypassed)
  2. type j. (and two chars are ok, but the keyboard adds a space after the '.')
  3. press left keyboard (to position the cursor just after the '.')
  4. press caps to lock twice (to remove again the capital constraint after '.')
  5. type doe

and I am done, but for an inexpert user, this is unacceptable (especially (1), (3), and (4)).

Somehow I would like that the keyboard behaves like one typing in a password field (no Caps Lock automatically activated and no spaces added after '.').

I did not manage to find a solution, does anyone knows a way to achieve the result?

Thanks!

Is there a way to inform the mobile keyboard on a mobile device that the possible values for an HTML input field are a subset of the possible values?

I try to express myself better with an example.

Let's say i have a username input text:

<input type="text" id="username">

when trying to type with a mobile device the mobile keyboard will do three non desired things:

  1. it tries to make me start typing a capital letter as the first char
  2. it adds a space after a "."
  3. it tries to make me start typing a capital letter after a '.'

So if I want to type j.doe (an example of a typical username)

and I type (one at a time): j . d o e I obtain J. Doe

I could, being an advanced mobile keyboard user, try to obtain the desired results by doing (for example on Swiftkey that has navigation arrows):

  1. press caps lock twice (so the first letter capital constraint is bypassed)
  2. type j. (and two chars are ok, but the keyboard adds a space after the '.')
  3. press left keyboard (to position the cursor just after the '.')
  4. press caps to lock twice (to remove again the capital constraint after '.')
  5. type doe

and I am done, but for an inexpert user, this is unacceptable (especially (1), (3), and (4)).

Somehow I would like that the keyboard behaves like one typing in a password field (no Caps Lock automatically activated and no spaces added after '.').

I did not manage to find a solution, does anyone knows a way to achieve the result?

Thanks!

Share Improve this question edited Nov 15, 2021 at 12:33 Denis Tabac 431 silver badge4 bronze badges asked Nov 12, 2021 at 11:39 UnDiUdinUnDiUdin 15.4k40 gold badges161 silver badges258 bronze badges 1
  • 1 you could manipulate the input no matter what the keyboard does, for example trim the text and lowecase it on keyup event – john Smith Commented Nov 15, 2021 at 9:54
Add a ment  | 

4 Answers 4

Reset to default 2

I googled "ios input lowercase" and this was the first hit:

iPhone browser defaulting to uppercase for first letter of password fields

In short, add the attributes autocapitalize="none" on the input field, and throw in a autoplete="off" and autocorrect="off" for good measures.

You will need to add autocorrect and autocapitalize props to the input tag and set them to be disabled.

Ex:

<input type="text" id="username" autocorrect="off" autocapitalize="none">

Blog with explanation on the same

or onkeydown you could convert the keyed value to lowercase

onkeydown = function keyDown(e) {
  
  let keyPressed =  String.fromCharCode(e.keyCode).toLowerCase();
  .....

};

To be really sure that the field is not capitalize you can set its type to be email

<input type="email" id="loginId"  autocapitalize="off"   autoplete="off"  spellcheck="false"  autocorrect="off"/>

No validation is done, so you can still enter a username in a "email" field.

to obtain this in JS

var loginInput=document.getElementById("loginId");
loginInput.setAttribute("type","email");

Try turning off mobile auto fix-ups using these HTML attributes:

<input type="text" id="username"
  autocapitalize="off" 
  autoplete="off"
  spellcheck="false" 
  autocorrect="off"/>

source: https://weblog.west-wind./posts/2015/jun/15/turn-off-html-input-auto-fixups-for-mobile-devices

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744835923a4596260.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信