A.I. oddity when adding events?

I am using the included Codex model, and I asked it to handle an event in a text area. This is what it did :

self._numbers_keydown_handler = anvil.js.report_exceptions(self.text_area_numbers_keydown)
anvil.js.get_dom_node(self.text_area_numbers).addEventListener(
  "keydown", self._numbers_keydown_handler
)

Now, it works. But I would have thought it would have used a more “anvillic” method of adding events rather than adding it to the dom node?

I’ve been adding quite a lot of code recently using AI and I’ve not checked all of it. Whilst it all works (and works well), I wonder if it’s doing other non-avillic things?

Anyone else seen this? Is it to be expected?

edit - maybe there’s a better way to prompt it to get it to follow anvil style, but the agent instructions seem to steer it towards anvil-style.

1 Like

Agents are certainly told about using Anvil event handlers. One thing you might want to ask is

Why didn’t you use the @anvil.handle decorator on the Textarea compoent’s change event?

I’d be curious to see what it says.

We’ll add this case internally to see if we can reproduce it and improve our Agent workflow.

Ref. your PM to me - this is a non-problem I think. For the benefit of anyone else reading this - I asked it to add an event that does not exist in Anvil for that type of control (ctl-enter on textarea), so it created it, and it does work.

2 Likes