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

    mysterious-toddler-20573

    01/30/2023, 3:39 PM
    it would be easier to do this with an included parameter rather than changing the url
  • r

    rich-coat-84078

    01/30/2023, 3:49 PM
    Thank you, Deniz. I'll work on it.
  • r

    rich-coat-84078

    01/30/2023, 3:52 PM
    You mean something like this? hx-include="[id=25]"
  • r

    rich-coat-84078

    01/30/2023, 3:59 PM
    I just realized, I'm already using "Template Fragments" > Django Render Block Extension. that's where the problem started. i can't pass url by id for hx-get unfortunately :/
  • m

    mysterious-toddler-20573

    01/30/2023, 4:01 PM
    can you use a morphing option here?
  • m

    mysterious-toddler-20573

    01/30/2023, 4:02 PM
    can you give us an idea of what you are doing in the UI? This seems more complicated than may be necessary
  • m

    mysterious-toddler-20573

    01/30/2023, 4:02 PM
    maybe some screen shots?
  • l

    lively-waitress-29714

    01/30/2023, 4:05 PM
    I tried, but my actual project uses
    hx-trigger="load delay:1s"
    coupled with
    hx-swap="outerHTML"
    ("load polling", according to the htmx docs), which doesn't seem to work well with morphing. The morphing libraries did their job, but since the outer div didn't refresh, the
    load delay
    trigger only works once. However, I'm curious why
    hx-preserve
    doesn't work either.
  • m

    mysterious-toddler-20573

    01/30/2023, 4:06 PM
    unfortunately, hx-preserve does keep the same node in the UI, but browsers sometimes reset state when a node is moved between parent nodes. It's inconsistent, even between browser versions: sometimes animated images have worked, sometimes not. Video elements have never worked. So morphing is the only real option (and the DOM needs to be similar enough that a morph can preserve the parent hierarchy)
  • m

    mysterious-toddler-20573

    01/30/2023, 4:06 PM
    super annoying
  • m

    mysterious-toddler-20573

    01/30/2023, 4:07 PM
    can you switch to regular polling rather than load polling?
  • m

    mysterious-toddler-20573

    01/30/2023, 4:07 PM
    Or does it terminate at some point?
  • l

    lively-waitress-29714

    01/30/2023, 4:10 PM
    It does terminate, it's essentially waiting for a process to complete on the backend and shows a spinner amongst some text during that period. My issue with morphing was that it only morphed once, I guess afterwards it didn't trigger another "load" due to the outer element remaining the same.
  • m

    mysterious-toddler-20573

    01/30/2023, 4:10 PM
    Yep
  • l

    lively-waitress-29714

    01/30/2023, 4:10 PM
    Is there any other way to solve that? I thought it's a rather common pattern
  • m

    mysterious-toddler-20573

    01/30/2023, 4:11 PM
    Yes, you can do normal polling and then send a
    286
    response code when you want it to stop polling: https://htmx.org/docs/#polling
  • m

    mysterious-toddler-20573

    01/30/2023, 4:11 PM
    Another option is moving the spinner outside the content being poll updated, and then removing it when it completes w/ something like an out of band swap
  • l

    lively-waitress-29714

    01/30/2023, 4:12 PM
    Ah, right. Can I include new content within that final 286 response which is then swapped?
  • l

    lively-waitress-29714

    01/30/2023, 4:16 PM
    Is that possible without additional JS and without keeping state on the server (whether the spinner has already been sent to the client)? I tried that, but without state my endpoint either returns the spinner with each request - which resets it - or it doesn't include the spinner at all, which would probably require some JS to add it manually to the DOM
  • m

    mysterious-toddler-20573

    01/30/2023, 4:19 PM
    it seems like the logic would be something like this:
    Copy code
    if process.is_finished
      render "list_of_stuff"  + "<div id='spinner'></div>"
    else
      render "list_of_stuff"
    end
    </div>"
  • m

    mysterious-toddler-20573

    01/30/2023, 4:19 PM
    where if the process is finished you include a small bit of oob content to empty out the spinner
  • m

    mysterious-toddler-20573

    01/30/2023, 4:20 PM
    for this UI, I would consider expanding the target to enclose both the side panel and the table
  • m

    mysterious-toddler-20573

    01/30/2023, 4:21 PM
    that would simplify things quite a bit
  • r

    rich-coat-84078

    01/30/2023, 4:21 PM
    There is no problem in the item create process, because it does not ask for any id, but when I do it with template fragment in the update process, I need to pull the whole list. If I pull the whole list, there is no problem, but I want to change a row in the list. For example I want only row two to change instead of the whole list.
    Copy code
    <list hx-get=whole list>
        <row 1 >
        <row 2 >
        <row 3 >
    </list>
  • m

    mysterious-toddler-20573

    01/30/2023, 4:22 PM
    I would bet that if you did a perf analysis, just re-rendering the whole list would be a round off error in your overall app performance profile
  • m

    mysterious-toddler-20573

    01/30/2023, 4:23 PM
    my philosophy is to keep it as simple as possible until a perf issue comes up in perf testing or production
  • m

    mysterious-toddler-20573

    01/30/2023, 4:23 PM
    You could put a trigger on each row for a specific event for that row
  • r

    rich-coat-84078

    01/30/2023, 4:24 PM
    yes, re-rendering the whole list will make things much easier. but then the joy of using the interface will be lost :/
  • m

    mysterious-toddler-20573

    01/30/2023, 4:24 PM
    Copy code
    <tr hx-get="/product/32/row" hx-trigger="product-updated:32 from:body">
      ...
    </tr>
  • m

    mysterious-toddler-20573

    01/30/2023, 4:24 PM
    I don't think you'd notice a difference
1...100210031004...1146Latest