Question

I have a textArea and would like to prevent the default behavior for certain keys such as the enter key from being run upon user input. However, KeyboardEvent is not cancelleable so preventDefault does not work. Does anyone know how this could be done?

Was it helpful?

Solution

Think I found a pretty easy workaround just using the TextInput event which is cancelleable and does the trick for the enter key. Also, TextInput event doesn't fire for the backspace key, which doesn't affect what I'm trying to do here but fyi.

OTHER TIPS

Something like this might work? i haven't tried this my self tho.

textArea.addEventListener(TextEvent.TEXT_INPUT,onTextInput);

private function onTextInput(e:TextEvent):void {
   if (e.text == '\n') e.preventDefault();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top