compositionend Commits IME Input
compositionend carries the IME-committed string, so validators can skip compositionupdate drafts and check only final input values.
Code
// IME composition: the input holds in-progress text until the IME commits
const input = document.querySelector('#name');
input.addEventListener('compositionstart', () => {
input.dataset.composing = 'true';
console.log('composing started');
});
input.addEventListener('compositionupdate', (event) => {
console.log('draft:', event.data);
});
// compositionend fires with the committed string before the final input event
input.addEventListener('compositionend', (event) => {
input.dataset.composing = 'false';
console.log('committed:', event.data);
});
input.addEventListener('input', () => {
// Skip partial IME drafts: only committed text is validated
if (input.dataset.composing === 'true') return;
console.log('validated:', input.value.length, 'chars');
});How it works
Top-level bindings input hold the demo state — nothing sits inside a function scope.
What to watch for
- Zero-fetch snippet: every identifier resolves inside the language distribution.
- The snippet leans on
document— browser-only surfaces a bare Node process cannot provide. - The guard
input.dataset.composing === 'true'stops the pass immediately with an earlyreturnwhen its condition holds.
Using it
Output lines are prefixed (composing started, draft:, committed:), so every step’s effect is easy to pick out.
Key statements worth quoting
input.addEventListener('compositionupdate', (event) => {
console.log('draft:', event.data);
});
input.addEventListener('compositionend', (event) => {
input.dataset.composing = 'false';
console.log('committed:', event.data);
});
input.addEventListener('compositionstart', () => {
input.dataset.composing = 'true';
console.log('composing started');
});
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.DOM Event Propagation VisualizerVisualize DOM event capturing, targeting, and bubbling phases in real time. Toggle stopPropagation and stopImmediatePropagation to see how events traverse the tree.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 compositionend Commits IME Input 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.