Pressed_enter event for TextArea?

Is there a (hacky) way to mimic the behaviour of the pressed_enter event of a TextBox but for a TextArea component which doesn’t have that event?

Yes. Anvil-extras has a way to do this
see
https://anvil-extras.readthedocs.io/en/latest/guides/modules/augmentation.html

or can just do this yourself, with something like

from anvil.js import get_dom_node


...

  def __init__(self, **properties):
    ...
    ta_dom = get_dom_node(self.text_area_1)
    ta_dom.addEventListener("keydown", self.ta_keydown)

  def ta_keydown(self, e):
    if e.key == "Enter" and not e.shiftKey:
      e.stopPropagation()
      e.preventDefault()
      # do something here

2 Likes