Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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();
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top