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

    shy-knife-59740

    03/26/2023, 11:44 PM
    they dont
    Copy code
    html
    <div>
        <form id="postform" hx-get="/posts" hx-target="#postlist">
            <select name="sort">
                <option value="id">id</option>
                <option value="date">date</option>
            </select>
            <select name="order">
                <option value="asc">ascending</option>
                <option value="desc">descending</option>
            </select>
        </form>
    </div>
  • m

    mysterious-toddler-20573

    03/26/2023, 11:44 PM
    OK, if you do that, then you'll need to add an
    hx-trigger="change"
  • m

    mysterious-toddler-20573

    03/26/2023, 11:45 PM
    Oh, wait, this is a GET
  • s

    shy-knife-59740

    03/26/2023, 11:45 PM
    yes it is
  • m

    mysterious-toddler-20573

    03/26/2023, 11:45 PM
    yeah, so moving it onto the form them is the right thing
  • m

    mysterious-toddler-20573

    03/26/2023, 11:45 PM
    but add the
    hx-trigger
    so it will submit when a select changes
  • m

    mysterious-toddler-20573

    03/26/2023, 11:45 PM
    rather than the default (which is
    submit
    for forms)
  • s

    shy-knife-59740

    03/26/2023, 11:45 PM
    on the whole form?
  • s

    shy-knife-59740

    03/26/2023, 11:46 PM
    oh yea that worked haha
  • m

    mysterious-toddler-20573

    03/26/2023, 11:46 PM
    Copy code
    html
    <form id="postform" 
          hx-get="/posts" 
          hx-target="#postlist"
          hx-trigger="change">
  • m

    mysterious-toddler-20573

    03/26/2023, 11:47 PM
    if you add a submit button (or want to use some other event in addition to "change") you can use commas to separate them:
    Copy code
    html
    <form id="postform" 
          hx-get="/posts" 
          hx-target="#postlist"
          hx-trigger="submit, change">
  • s

    shy-knife-59740

    03/26/2023, 11:48 PM
    i completely forgot about hx-trigger, i thought only select tags would work with a change event
  • m

    mysterious-toddler-20573

    03/26/2023, 11:48 PM
    if things get more complicated than that, I usually recommend doing some scripting to trigger a custom event in the situations you want and then make
    hx-trigger
    listen for that custom event
  • m

    mysterious-toddler-20573

    03/26/2023, 11:48 PM
    hx-trigger can respond to any event, and the
    change
    event will bubble up from the
    select
    to the
    form
    tag, so it will work
  • s

    shy-knife-59740

    03/26/2023, 11:48 PM
    damn thats interesting
  • s

    shy-knife-59740

    03/26/2023, 11:48 PM
    also, based avatar
  • m

    mysterious-toddler-20573

    03/26/2023, 11:49 PM
    it accurately captures my mental states on most days
  • s

    shy-knife-59740

    03/26/2023, 11:51 PM
    a sacrifice for being a discord mod
  • s

    shy-knife-59740

    03/26/2023, 11:52 PM
    /j
  • Hum, when I send a 422 response with a Reswap and Retarget, the before/afterRequest events seem to stop working.
    e

    eager-plumber-49649

    03/29/2023, 3:51 PM
    Hum, when I send a 422 response with a Reswap and Retarget, the before/afterRequest events seem to stop working.
  • Had no time to debug this.
    e

    eager-plumber-49649

    03/29/2023, 3:51 PM
    Had no time to debug this.
  • Will report
    e

    eager-plumber-49649

    03/29/2023, 3:51 PM
    Will report
  • I was stupid and redeclared a test variable
    e

    eager-plumber-49649

    03/29/2023, 7:59 PM
    I was stupid and redeclared a test variable
  • Hi. Having a strange problem with a very simple form. The form looks like this: form id="contact-form" hx-post="/contact" hx-target="#message" hx-swap="innerHTML" method="post">
    b

    blue-ram-58496

    03/29/2023, 9:37 PM
    Hi. Having a strange problem with a very simple form. The form looks like this: form id="contact-form" hx-post="/contact" hx-target="#message" hx-swap="innerHTML" method="post">
  • The HTML itself is fine, I've left most of it out to keep the chat short.
    b

    blue-ram-58496

    03/29/2023, 9:40 PM
    The HTML itself is fine, I've left most of it out to keep the chat short.
  • Is there a way to set a response header such that a given htmx request can ignore the specified `hx-target`?
    a

    aloof-xylophone-31768

    03/30/2023, 7:16 AM
    Is there a way to set a response header such that a given htmx request can ignore the specified
    hx-target
    ?
  • `Hx-Reswap`, `Hx-Retarget` https://htmx.org/reference/#response_headers
    r

    ripe-action-67367

    03/30/2023, 7:20 AM
    Hx-Reswap
    ,
    Hx-Retarget
    https://htmx.org/reference/#response_headers
  • Worst case is I would store the data from one action in session state and access with other action, but hoping HTMX has cleaner path built in. Will try out your suggestion
    a

    aloof-xylophone-31768

    03/30/2023, 7:28 AM
    Worst case is I would store the data from one action in session state and access with other action, but hoping HTMX has cleaner path built in. Will try out your suggestion
  • htmx can't be used to download files (without some extensive JS plumbing). Ideally, you would have download button submitting form as normal, outside of htmx flow. You also could use HX-Redirect, so that the browser will be redirected to download URL after htmx request, but that assumes you store your pdfs somewhere and allow to download them with GET request
    r

    ripe-action-67367

    03/30/2023, 7:33 AM
    htmx can't be used to download files (without some extensive JS plumbing). Ideally, you would have download button submitting form as normal, outside of htmx flow. You also could use HX-Redirect, so that the browser will be redirected to download URL after htmx request, but that assumes you store your pdfs somewhere and allow to download them with GET request
  • Yeah, had already wrangled with this for several other parts of the project, and each case ended up having the pdf button be outside HTMX. But elsewhere there wasn't a preview element that really builds on htmx. Even `HX-reswap` didn't work, doesn't render it to screen but leavex it marooned in response, pdf data never makes it to downloading. Thanks for the tip, though, reswap looks useful!
    a

    aloof-xylophone-31768

    03/30/2023, 7:39 AM
    Yeah, had already wrangled with this for several other parts of the project, and each case ended up having the pdf button be outside HTMX. But elsewhere there wasn't a preview element that really builds on htmx. Even
    HX-reswap
    didn't work, doesn't render it to screen but leavex it marooned in response, pdf data never makes it to downloading. Thanks for the tip, though, reswap looks useful!
1...108110821083...1146Latest