Cancelable event emitted as 'beforeinput' right before text is mutated or an undo/redo is applied — the same contract the DOM uses: call preventDefault() inside a listener to block the operation.
'beforeinput'
preventDefault()
textField.on('beforeinput', (event) => { if (event.inputType === 'insertText' && event.data === '!') { event.preventDefault(); // reject exclamation marks } if (event.inputType === 'historyUndo') { event.preventDefault(); // handle undo yourself }}); Copy
textField.on('beforeinput', (event) => { if (event.inputType === 'insertText' && event.data === '!') { event.preventDefault(); // reject exclamation marks } if (event.inputType === 'historyUndo') { event.preventDefault(); // handle undo yourself }});
Readonly
Text being inserted (insertText/insertFromPaste), null for deletions and history.
insertText
insertFromPaste
The keyboard or clipboard event that triggered the operation.
Cancelable event emitted as
'beforeinput'right before text is mutated or an undo/redo is applied — the same contract the DOM uses: callpreventDefault()inside a listener to block the operation.Example