https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • r

    refined-manchester-67193

    02/19/2023, 8:05 PM
    A few questions about the websocket extension: - Any reason I'm not able to connect when I put
    hx-ext="ws" ws-connect="/"
    directly on the
    body
    element? Putting it on a div inside of body did help. - I thought the item we're replacing has to be enclosed inside the item that has those HTML (
    hx-ext="ws"...
    ) attrs, but I was able to replace an item outside of it, which is solved the above issue....?
  • r

    refined-manchester-67193

    02/19/2023, 8:05 PM
    Ah, perhaps because my body already has
    hx-ext="debug"
    ?
  • o

    orange-umbrella-16693

    02/19/2023, 9:49 PM
    I think the position of ws-connect only matters if you have several ws connections, because ws-send sends the message to the closest parent element "containing" a ws connection As per doc > ws-send - Sends a message to the nearest websocket based on the trigger value for the element > […] > In the example above, the form uses the ws-send attribute to indicate that when it is submitted, the form values should be serialized as JSON and send to the nearest enclosing WebSocket, in this case the /chatroom endpoint. Otherwise the response is all out of bounds swaps that can go wherever the element's ID points them to, there is no bounds checking there I'm afraid > Content that is sent down from the websocket will be parsed as HTML and swapped in by the id property, using the same logic as Out of Band Swaps.
  • r

    ripe-action-67367

    02/19/2023, 10:29 PM
    If you want multiple extensions on the same element, use hx-ext="debug,ws"
  • r

    ripe-action-67367

    02/19/2023, 10:31 PM
    The location of element being replaced does not matter. ws messages are processed as OOB swaps which means you can target any element on the page, as you would with normal OOB response. What matters are the elements that send messages, like forms and buttons with ws-send. They must be enclosed in ws-connect element, and they will use the closest parent with this attribute
  • r

    refined-manchester-67193

    02/19/2023, 10:38 PM
    Helpful and clear as always, thanks!
  • e

    eager-psychiatrist-68229

    02/20/2023, 10:43 AM
    hey y'all, simple question: is it possible to get a hx-redirect to open in a new tab ?
  • s

    some-airline-73512

    02/20/2023, 11:24 AM
    @ripe-action-67367 Hi. I've done my work with
    hx-swap-oob="true"
    as you have suggested and it works great for deletion. The problem I have is when I want to append/prepend element to some other selector. I use
    hx-swap-oob="afterend:#selector"
    , but it replaces innerHTML instead of outerHTML. So this means that I have to wrap it in some , is that correct? Is there a way to specify like
    hx-swap-oob="afterend:outerHTML:#selector"
    ?
  • r

    ripe-action-67367

    02/20/2023, 11:33 AM
    Basically, yes https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L727-L729. Not sure if a template tag will work, but a simple div should certainly suffice
  • s

    some-airline-73512

    02/20/2023, 11:36 AM
    Thanks 🙏
  • s

    some-airline-73512

    02/20/2023, 11:52 AM
    @ripe-action-67367 I've tried that, it kinda breaks now. My response looks like this:
    Copy code
    <div hx-swap-oob="afterend:#t0">
        <tr id="..">
            <td>internals of cells from response</td>
            <td>internals of cells from response</td>
        </tr>
    </div>
    response body goes on ...
    And in the page there is:
    Copy code
    <table>
        <tbody>
            <tr id="t0"></tr>
            ... the rest of the rows
        </tbody>
    </table>>
    So after swap it looks like:
    Copy code
    <table>
        <tbody>
            <tr id="t0"></tr>
            <td>internals of cells from response</td>
            <td>internals of cells from response</td>
            ... the rest of the rows
        </tbody>
    </table>>
  • r

    ripe-action-67367

    02/20/2023, 11:53 AM
    ooof, you got tables
  • r

    ripe-action-67367

    02/20/2023, 11:54 AM
    yeeeaaaa, this is problematic
  • s

    some-airline-73512

    02/20/2023, 11:54 AM
    I really need this. In the past I was re-rendering the full tbody, but now I'm in optimization phase before shipping v1. And I need this to be fast, cannot afford rendering full body
  • r

    ripe-action-67367

    02/20/2023, 11:55 AM
    did you try template tag?
  • s

    some-airline-73512

    02/20/2023, 11:55 AM
    Yes, with template just nothing happens
  • s

    some-airline-73512

    02/20/2023, 11:55 AM
    No swap performed at all
  • r

    ripe-action-67367

    02/20/2023, 11:56 AM
    Just a second
  • r

    ripe-action-67367

    02/20/2023, 12:00 PM
    Okay
  • r

    ripe-action-67367

    02/20/2023, 12:00 PM
    I think I got something
  • r

    ripe-action-67367

    02/20/2023, 12:00 PM
    Wrap your row in the response in tbody like so
    Copy code
    html
    <tbody hx-swap-oob="afterend:#row1">
        <tr id="row2">
            <td>internals of cells from response</td>
            <td>internals of cells from response</td>
        </tr>
      </tbody>
  • r

    ripe-action-67367

    02/20/2023, 12:01 PM
    this is so dumb, but table parsing in html is so fragile, I actually can't believe this works
  • s

    some-airline-73512

    02/20/2023, 12:02 PM
    @ripe-action-67367 oh my god, you are Genius! It works. I owe you now
  • s

    some-airline-73512

    02/20/2023, 12:04 PM
    @ripe-action-67367 send me your USDT, I will send you my thank you
  • p

    proud-librarian-99598

    02/20/2023, 12:28 PM
    https://www.robinwieruch.de/web-development-trends/ mentions htmx at the very end.
  • a

    astonishing-cpu-59399

    02/20/2023, 1:10 PM
    I can get
    hx-target
    element in afterSwap event from
    evt.detail.target
    . But, if I change the target in beforeSwap event like
    evt.detail.target = htmx.find("#result_1");
    then I don't get the new target in afterSwap from
    evt.detail.target
  • a

    astonishing-cpu-59399

    02/20/2023, 1:13 PM
    https://jsfiddle.net/0dntf69y/6/
  • e

    early-notebook-68765

    02/20/2023, 6:22 PM
    I have tried adding a beforeSwap listener in the hope that I would see when a swap was about to occur as a result of a server sent event using sse extension. The listener is not triggered. Is there a way to do this? What I was hoping to do is accept some JSON as a sse event and process the JSON rather than just do a swap.
  • m

    mysterious-toddler-20573

    02/20/2023, 10:02 PM
    https://github.com/bigskysoftware/htmx/pull/1250
  • m

    mysterious-toddler-20573

    02/20/2023, 10:02 PM
    opinions?
1...102510261027...1146Latest