Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HTML 5 to change the keyboard language on mobile devices

I have bilingual HTML 5 form, and I am using the type attribute to help change the keyboard layout for mobile devices.

<input type="tel" />
<input type="email" />
<input type="?" />

This is working fine, as the tel value is showing a numbers keypad, and the email is showing a custom keyboard for email typing.

But I'm wondering if there is a way to specify the language of the input, so the device switches to the appropriate keyboard ?

I've randomly tried this :

<input type="text" lang="ar" />

But nothing happened, is this even possible in HTML5 or Javascript ?

like image 863
TheByeByeMan Avatar asked Feb 21 '20 10:02

TheByeByeMan


People also ask

How do I change keyboard layout language?

Keyboard shortcut: To switch between keyboard layouts, press Alt+Shift. Note: The icon is just an example; it shows that English is the language of the active keyboard layout. The actual icon shown on your computer depends on the language of the active keyboard layout and version of Windows.

How do I keep my mobile keyboard from covering HTML input?

Adding a padding to the bottom of the page that is large enough for the keyboard enables content to be displayed as desired when the keyboard is visible. Using some javascript listeners and a CSS class, this padding can be added only when the keyboard is displayed.


2 Answers

I think this's not really possible ,the problem you will encounter is that the keyboard is itself an application depends on the users locale , therefore you cannot change it directly from your web html page, nor can you guarantee that your user will have the "Arabic" charset and the keyboard depends alos on mobile device OS

Here's an example for html mobile input type :

http://mobileinputtypes.com/

like image 164
e2rabi Avatar answered Sep 16 '22 11:09

e2rabi


In extend to e2rabi and Srikara B S, it's indeed not possible but there might be a workaround.

In one of the applications that's being build by my employer, they wanted a strict character set to be used. They basically set all inputs to contain the disabled property, and on click(touch) render a custom keyboard. Because of the disabled attribute the keyboard won't trigger, and using (basic) Javascript you can fill the input with the keys used on your custom keyboard.

This isn't the most viable method, but since you can't force a users keyboard language (especially since an OS like Android allows custom keyboards), it might be your only option if you want to force a specific keyset or scheme/layout.

like image 38
GRX Avatar answered Sep 20 '22 11:09

GRX