inputMode And enterKeyHint For Mobile Keyboards
inputMode picks the virtual keyboard layout and enterKeyHint labels the action key, taming mobile form fields without changing the input type.
Code
const amountInput = document.querySelector('#amount') as HTMLInputElement;
const nextField = document.querySelector('#note') as HTMLInputElement;
// Numeric virtual keyboard with a decimal point, without number-input quirks.
amountInput.inputMode = 'decimal';
// Mobile keyboards label the action key "Next"; desktop browsers ignore it.
amountInput.enterKeyHint = 'next';
// Exact codes: no capitalization or correction help wanted.
amountInput.autocapitalize = 'off';
amountInput.spellcheck = false;
amountInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
event.preventDefault();
nextField.focus();
console.log('moved on; enterKeyHint is', amountInput.enterKeyHint);
}
});How the pieces connect — inputMode And enterKeyHint For Mobile Keyboards
Demo state sits in top-level bindings: amountInput, nextField.
Points of care
- The project needs no new pieces before this file can run.
- The snippet leans on
document— browser-only surfaces a bare Node process cannot provide.
Using it
The file’s steps show up in the output as moved on; enterKeyHint is.
Key statements
amountInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
event.preventDefault();
nextField.focus();
console.log('moved on; enterKeyHint is', amountInput.enterKeyHint);
}
});
Interactive Tools for This Topic
JSON to Zod Schema ConverterInfer typed Zod z.object schemas from JSON payloads locally, supporting nested objects, merged array shapes, enums, nullable fields, and JSDoc comments.IMEI ValidatorValidate 15-digit IMEI numbers with the Luhn checksum, with a full digit-by-digit computation trace and TAC/SNR field breakdown.JSON Schema ValidatorValidate JSON data against a JSON Schema definition and get detailed error reports. Supports type checking, required fields, and common constraint validation.JSONL / NDJSON InspectorValidate NDJSON and JSON Lines line-by-line, pinpoint syntax errors by line number, analyze key frequencies and types, and export a pretty JSON array.
FAQ
- Does inputMode And enterKeyHint For Mobile Keyboards run in plain Node.js?
- No — it touches `document`, which exist only in the browser. Run it in a page (or the DevTools console) instead of a bare Node process.
Report a problem with this exampleOpens a pre-filled issue on GitHub.