Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top