Вопрос

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