bigskysoftware / bigskysoftware/htmx

htmx:confirm with custom event drop hx-vals parameters when triggered by htmx.trigger

Open
#2,773 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

If an event listener is placed on "htmx:confirm" and then a issueRequest() is made the custom event parameters are lost from the htmx.trigger. If the issueRequest() is commented out the parameters are correctly passed through.

I just want to confirm this is correct usage for having a condition in "htmx:confirm" to cancel a request or allowing it.

I haven't investigated why issueRequest is doing this, but I assume the default behaviour would be the calling of this function.

[jsfiddle](https://jsfiddle.net/tatebluedogcomau/em1kqz2c/58/#&togetherjs=le72nyODv0)

```

document.body.addEventListener("htmx:load", function() {
htmx.trigger("#count", "count", { number: 10 })
})

document.body.addEventListener("htmx:confirm", async function (event) {
event.preventDefault()
// some condition to determine if the request will be made or cancelled
await event.detail.issueRequest()
})


Count Up


${JSON.stringify(params)}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.