Perhaps some of the most important UX considerations to make are those surrounding the simplicity with which forms can be completed. This is especially important when taking into account the constraints of Mobile devices.
Input Elements and the iOS Keyboard
While implementing a form for a Mobile Web Application, I found myself in need of a way to control some of the default behaviors of the native iOS Keyboard. Specifically, I found it rather inconvenient on the user’s part to require manual closing of the keyboard of any kind, especially after submitting a form. I also found it inconvenient to have to manually turn off auto capitalization on input elements, or having to work around the default auto-correct behavior on input elements.
Fortunately, these issues (as well as others) have solutions which are readily available, both natively and programmatically.
Turning off auto-caps
By default, the iOS Keyboard displays with Caps Lock on for the first charachter on input elements of type text. For certain use-cases, such as entering usernames, this may not be desirable.
Caps Lock can be turned off by simply defining an autocapitalize
attribute with a value of off
on input elements:
1 2 3 4 | <!-- disable auto-capitalize --> <input type="text" autocapitalize="off"> |
Turning off auto-correct
As with with Caps Lock, in iOS, by default, input elements of type text have auto-correct enabled. For certain use-cases, again, such as entering usernames, this may not be desirable.
Auto-correct can be disabled by simply defining an autocorrect
attribute with a value of off
on input elements:
1 2 3 4 | <!-- disable auto-correct --> <input type="text" autocorrect="off"> |
Automatically closing the Keyboard
When submitting a form, at times, the iOS Keyboard may not automatically close. This is quite a usability issue as Users should not be required to manually close the Keyboard for use-cases in which they would otherwise not expect the need do so.
A simple solution for this can be implemented by invoking the blur method on document.activeElement, which effectively allows one to programmatically hide the keyboard:
1 2 3 4 5 | // automatically close the keyboard on iOS document.activeElement.blur(); ... |
HTML5 Input Attribute Types
In addition to controlling the default behavior of the iOS Keyboard, specific types of Keyboards can be invoked simply by defining a supported HTML5 input element type.
The following examples demonstrate just how easy it is to display a context specific keyboard:
The Email keyboard can be invoked via the email input type:
1 2 3 4 | <!-- input element of type 'email' displays the iOS email keyboard --> <input type="email" placeholder="email keyboard" autocorrect="off"> |
The URL keyboard can be invoked via the url input type:
1 2 3 4 | <!-- input element of type 'url' displays the iOS URL keyboard --> <input type="url" placeholder="url keyboard" autocorrect="off"> |
The Telephone keyboard can be invoked via the tel input type:
1 2 3 4 | <!-- input element of type 'tel' displays the iOS telephone keyboard --> <input type="tel" placeholder="telephone keyboard" autocorrect="off"> |
The Numeric keyboard can also be invoked via the pattern attribute, the value of which being either of the following Regular Expressions [0-9]*
or \d*
:
1 2 3 4 | <!-- input element of type 'text' with pattern attribute displays the iOS numeric keyboard --> <input type="text" placeholder="numeric keyboard" pattern="[0-9]*" /> |
{Sorry, Comments are currently Closed! }