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?

有帮助吗?

解决方案

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.

其他提示

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();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top