htmx
htmx copied to clipboard
hx-vals does not work together with delay
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
}
I have also noticed this problem
any update on this issue ? any work around ?
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>
fixed in 2.0.2
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.