htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Class tools extension question

Open constantin-webc opened this issue 4 years ago • 7 comments

First, thank you for HTMX

my question is certainly more due to a bad understanding on my part than an issue.

If I take the example of the toggle class It will only work if I add an attribute hx-get or hx-post.

Actually using HTMX without these attributes doesn't really make sense, but I was wondering if that was a bug or a misunderstanding on my part.

On the Demo page, the attributes are not present on the toggle demo and works fine.

Thank you for your help and reply.

Best wishes to all.

constantin-webc avatar Dec 31 '20 19:12 constantin-webc

That seems like a bug. Looking at the source code it looks like it should work on any element, even if you don't have an hx-get.

I will try to get a chance to debug this tomorrow.

1cg avatar Dec 31 '20 23:12 1cg

Thank you.

constantin-webc avatar Jan 01 '21 05:01 constantin-webc

Just in case it might help, with htmx update, class tools does not work even if there is an hx-get or hx-post

constantin-webc avatar Jan 07 '21 06:01 constantin-webc

I have a problem with class-tools too.

I tried to use class-tools toggle in my website. I have added the extension to the body. When I copy paste the example inside the body it's ok, it works. But when I try to do the same thing in an ajax generated html component, it does not works, I can't figure why.

Bonten156 avatar Jun 21 '21 12:06 Bonten156

why doesn't it work if there is no hx-get?

fess932 avatar Oct 10 '21 15:10 fess932

Can you set a breakpoint here:

https://github.com/bigskysoftware/htmx/blob/ecce4f19d4792f324f5fffc4cd80daeee45cce78/src/ext/class-tools.js#L73

And see if the classes attribute is being properly handled?

1cg avatar Oct 12 '21 15:10 1cg

Just bumping this with another example:

I'm using the websocket extension which requires hx-swap-oob, so to get transition animations I need more than just setting a settle/swap delay like I would with a regular hx-swap (because hx-swap-oob doesn't support all hx-swap values despite what the documentation says).

So with my use case for a simple chat, a single message element looks something like this:

<div hx-swap-oob="beforeend" id="chat_transcript">
  <div class="myclass ..."
       classes="remove myclass:1s">
    <p>{{ message }}</p>
  </div>
</div>

classes doesn't seem to work here either, myclass doesn't get removed.

What's now line 81 for the evt.detail.elt line doesn't seem to get fired at all.

ekaj2 avatar Jan 21 '24 06:01 ekaj2