bigskysoftware / bigskysoftware/htmx
hx-trigger response header
- Dominant language
- JavaScript
- Stars
- 49.4k
- Forks
- 1.7k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 30
Description
Hi guys,
i was trying to trigger multiple events via the HX-Trigger response header. Reading the docs and looking at the [code](https://github.com/bigskysoftware/htmx/blob/f42117628cc994fbc250c7b69c76bf4ca24d46a2/src/htmx.js#L2025) i know i can trigger either by comma separated list like so ```event1, event2, ...``` or have a json object with the event names as root level properties like so ```{"event1": "foo", "event2": {"myDetail": "bar"}}```
My Problem is that this means I have to keep track of the hx-trigger response headers set in my application. If I want to trigger multiple events and one of them wants to use extended json details I'll have to merge all the events into one json object. I can not just set multiple hx-trigger headers, since they will be concatenated and separated by comma (,) as stated in (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getResponseHeader).
A possible solution would be to always split the header at comma taking into account that the comma must not be enclosed by curly braces. Similarly to how it is already done for the "no json" case. the resulting array then could be handled one item at a time parsing json if applicable.
I could draw up a pr if wanted.
Cheers!
Contributor guide
Assessment
This issue has not been assessed yet.