Repository navigation
Why do camel-case events not work when using Alpine.js? #2843
Unanswered
danielniccoli
asked this question in
Q&A
Replies: 1 comment
|
One gotcha to note is that DOM attributes do not preserve case. This means, unfortunately, an attribute like hx-on:htmx:beforeRequest will not work, because the DOM lowercases the attribute names. Fortunately, htmx supports both camel case event names and also kebab-case event names, so you can use hx-on:htmx:before-request instead. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am using both, HTMX and Alpine.js. I added
hx-on:htmx:afterSwap="console.log('boop')"to an element and it doesn't work. When replacing the camel-case with kebap-casehx-on:htmx:after-swap="console.log('boop')"the event is now handled as expected.I understand that both events are always fired. And that AlpineJS requires kebap-case ("This facilitates interoperability with other libraries. Alpine.js, for example, requires kebab case."). But I'm using HTMX's event handler (
hx-on) and not Alpine.js' (x-on). So why does the HTMX event handler not handle theafterSwapevent?Is this behaviour expected?
All reactions