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

    brainy-ice-92385

    07/20/2022, 4:55 PM
    See reply above, that's the preferred solution, and if that doesn't work, the event system is described here https://htmx.org/docs/#events and all the events are outlined here https://htmx.org/reference/#events
  • m

    mysterious-toddler-20573

    07/20/2022, 6:04 PM
    in the
    htmx:configRequest
    you can look at the
    detail.headers
    to see if
    HX-Boosted
    header is present
  • w

    witty-garage-37227

    07/20/2022, 6:07 PM
    Thanks, what I was looking for
  • m

    mysterious-toddler-20573

    07/20/2022, 7:39 PM
    https://twitter.com/joekaufeld/status/1549838597624369152
  • a

    adamant-state-54102

    07/20/2022, 10:28 PM
    I have a URL
    /download
    which is setup to trigger the download of a file, if you navigate directly to it in your browser. I would like to
    hx-get
    it somehow, so I can use
    hx-indicator
    while the file is prepared on the server, but still have it trigger the browser's native download functionality when it receives the response. Is this possible somehow?
  • m

    mysterious-toddler-20573

    07/20/2022, 10:32 PM
    Unfortunately not really. The best you can do is have
    /download
    produce a progress UI and then, when it is done, do a client-side redirect to, say
    /download/finished
  • m

    mysterious-toddler-20573

    07/20/2022, 10:32 PM
    polling
    /download
    would be the easiest
  • a

    adamant-state-54102

    07/20/2022, 10:37 PM
    @mysterious-toddler-20573 So if I just make it a link (nothing to do with htmx), here's what happens: I click, short pause, download starts and completes, then I remain on the page where I was. This is exactly what I want, except I want the button disable during the short pause to prevent double clicks / give the user feedback. I don't mind using some vanilla JS, but I don't know which browser API, if any, I can use to determine that "hey, that link wasn't a navigable link but a download response, and now the dload is finished". do you know if there is any, just from your general knowledge of browser tech, unrelated to htmx?
  • m

    mysterious-toddler-20573

    07/20/2022, 10:38 PM
    There isn't an API for that unfortunately
  • m

    mysterious-toddler-20573

    07/20/2022, 10:38 PM
    If you like the current behavior you can use a client side script to disable the button on click
  • m

    mysterious-toddler-20573

    07/20/2022, 10:40 PM
    https://codepen.io/1cg/pen/WNzjZQa
  • a

    adamant-state-54102

    07/20/2022, 10:40 PM
    > If you like the current behavior you can use a client side script to disable the button on click Right, and that would work great, but then I don't know when to re-enable.... That's what I am trying to figure out.
  • m

    mysterious-toddler-20573

    07/20/2022, 10:40 PM
    Oh, ah, yeah, that's impossible 🙂
  • m

    mysterious-toddler-20573

    07/20/2022, 10:43 PM
    To achieve exactly what you want, you'd need to create a polling-based API that checks as the download is processed, then issue a client side redirect when the download was ready to a URL (maybe using the
    HX-Redirect
    header) to start the actual download. You could then reenable the download button. I've created UIs like this. A bit of a pain but it's the correct UI pattern for this sort of stuff.
  • m

    mysterious-toddler-20573

    07/20/2022, 10:43 PM
    But it's work, so you have to ask yourself: is it worth it? grug often say no.
  • m

    mysterious-toddler-20573

    07/20/2022, 10:43 PM
    but not always
  • a

    adamant-state-54102

    07/20/2022, 10:45 PM
    @mysterious-toddler-20573 Thanks for the info, that's very helpful to know it can't be done. To answer your question, in this particular case, definitely not worth it. I can just a short note next to the button.
  • m

    mysterious-toddler-20573

    07/20/2022, 10:45 PM
    I did a quick search and found this: https://github.com/rndme/download
  • m

    mysterious-toddler-20573

    07/20/2022, 10:46 PM
    might be able to do what you want, looks like it's browser-specific
  • m

    mysterious-toddler-20573

    07/20/2022, 10:47 PM
    oof
  • m

    mysterious-toddler-20573

    07/20/2022, 10:47 PM
    there's a pretty good upload API at least! https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload
  • h

    handsome-gpu-11538

    07/21/2022, 12:26 AM
    Is there a way to specify two hx-target/hx-select pairs for a single call? I'm using django and want to update the small portion of the page, but also still display the django.contrib.messages (success/fail/etc) at the top of the page...
  • r

    refined-waiter-90422

    07/21/2022, 1:30 AM
    check out
    hx-select-oob
    or
    hx-swap-oob
  • r

    refined-waiter-90422

    07/21/2022, 1:32 AM
    hx-select-oob
    allows you to do a comma seperated list.
    hx-swap-oob
    will allow you to pre-select elements to swap.
  • m

    mysterious-tomato-195

    07/21/2022, 10:25 AM
    On
    hx-select-oob
    documentation it says "The value of this attribute is comma separated list of elements to be swapped out of band", but I can't make this work. If I use
    hx-select-oob="foo, bar"
    ,
    #foo
    gets replaced but I get an error saying that there's no
    # bar
    element (notice the space). If I use
    hx-select-oob="foo,bar"
    nothing gets replaced
  • m

    mysterious-tomato-195

    07/21/2022, 10:34 AM
    https://codepen.io/dariooddenino/pen/dymWoLm Basically I'd like to have something like this. I can't replace the whole content of the dropdown because I need the
    #notifications-dropdown
    scroll to not reset on each update, and to do so I need to replace its inner content only. Maybe I'm using the wrong approach completely
  • l

    lemon-grass-35120

    07/21/2022, 10:39 AM
    And if you try "#foo,#bar#"
  • l

    lemon-grass-35120

    07/21/2022, 10:39 AM
    Ignore the last #
  • m

    mysterious-tomato-195

    07/21/2022, 10:48 AM
    same
  • b

    brainy-ice-92385

    07/21/2022, 2:37 PM
    Your approach seems right. Seems like a bug
1...756757758...1146Latest