htmx icon indicating copy to clipboard operation
htmx copied to clipboard

hx-vals does not work together with delay

Open sigsegvat opened this issue 2 years ago • 2 comments

It seems that the event object is not passed to the jx-vals expression when using a delay modifier in hx-trigger (see code below).

<div contenteditable="true" hx-post="/test" contenteditable="true" hx-trigger="input delay:1s" 
     hx-vals="js:{text: convertEvent(event)}"
     >doesn't work</div>

<div contenteditable="true" hx-post="/test" contenteditable="true" hx-trigger="input" 
     hx-vals="js:{text: convertEvent(event)}"
     >works</div>
     
 window.convertEvent= function(event) {
  console.log(event)
  return event.target.innerHTML
}    

sigsegvat avatar Jan 03 '23 14:01 sigsegvat

I have also noticed this problem

GlennWSo avatar Sep 18 '23 10:09 GlennWSo

any update on this issue ? any work around ?

ahmed-com avatar Sep 15 '24 04:09 ahmed-com

Workaround:

<div contenteditable="true" hx-post="/test" contenteditable="true" hx-trigger="myinput" 
     hx-vals="js:{text: convertEvent(event)}"
     oninput="setTimeout(evt => htmx.trigger(evt.target, 'myinput', {cause: evt}), 1000, event)"
     ></div>

scrhartley avatar Feb 19 '25 15:02 scrhartley

fixed in 2.0.2

1cg avatar Jun 16 '25 22:06 1cg

I think it's a mistake saying that this was fixed in version 2.0.2. PR #3196 has been merged into the dev branch (Apr 24, 2025), but hasn't made its way to master yet for a release.

scrhartley avatar Jun 17 '25 12:06 scrhartley