htmx icon indicating copy to clipboard operation
htmx copied to clipboard

`hx-vals="js: { a: event.target.value }"` errs

Open reedspool opened this issue 3 years ago • 6 comments

Here's an example of the issue https://codepen.io/reedspool-gh/pen/XWYbRXo

For some reason, if clicking multiple times quickly, hx-vals="js:{ test: event.target.value }"> causes an error, TypeError: Cannot read properties of undefined (reading 'target') at htmx.org:1:29917. I narrowed this down to the execution of Function(...)() in getValuesForElement.

If you click the button slowly, the count will appear and then increase. But if you click it twice quickly, an error appears and the HTMX no longer triggers upon clicking this button ever again.

I think this is two problems:

  • If there is an htmx error, I think that should never stop the htmx event from triggering on the same element again
  • The specific error that appears must be a bug, right?

I narrowed the bug down to the second click having an event value of undefined instead of an actual event as expected.

reedspool avatar Oct 28 '22 08:10 reedspool

I'm having a similar issue, except in my case event is always undefined.

jquesada2016 avatar Aug 02 '23 01:08 jquesada2016

the delay causing the event to be undefined definitely caught me off-guard and had to spend some time debugging

@reedspool did u manage to work around it?

FeliciousX avatar Jun 17 '24 00:06 FeliciousX