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

    blue-gold-89534

    12/15/2022, 10:33 AM
    something like
    Copy code
    js
    document.querySelectorAll('id=form');.forEach(elem => { elem.setAttribute("style", "display:block;") });
    should work I guess (but I am a js noob)
  • b

    blue-gold-89534

    12/15/2022, 10:34 AM
    there are HTMX events: https://htmx.org/reference/#events
  • b

    blue-gold-89534

    12/15/2022, 10:35 AM
    https://htmx.org/headers/hx-trigger/
  • f

    freezing-controller-74032

    12/15/2022, 10:36 AM
    thanks bro
  • b

    brave-dog-98297

    12/15/2022, 11:08 AM
    You could always use hyperscript to change the attribute after the htmx load event
  • b

    brave-dog-98297

    12/15/2022, 11:09 AM
    Or return a custom htmx tag in your response to use as the trigger
  • b

    bitter-monkey-50309

    12/15/2022, 12:13 PM
    Would there be any appetite in adding another HTTP response header that overrides the behaviour of not swapping error responses? Something like
    HX-Swap-Error: true
    ? An example use case is when a user submits a form that fails validation I want to return the HTML of the form with the inline validation errors (including keeping the submitted values) but also use the 400 status code to make it clear in logs that it's failed validation. Adding it as a header means by backend can be responsible for determining whether it's able to return an error suitable for the target or not (no full page error dumped into a
    div
    intended for a partial. Currently I've got an event listener on
    beforeSwap
    that checks if the status is >= 400 and there's a custom response header to swap the error then it sets
    shouldSwap=true
    and
    isError=false
    . Be nice to bake that in IMO.
  • b

    boundless-vase-80440

    12/15/2022, 12:21 PM
    Can you make an extension for that?
  • b

    boundless-vase-80440

    12/15/2022, 12:21 PM
    Did I get the emoji right?
  • r

    ripe-ghost-5606

    12/15/2022, 12:25 PM
    I've done the exact same thing, baking it in would be good
  • b

    bitter-monkey-50309

    12/15/2022, 12:42 PM
    Good idea! I hadn't thought of that so I'm not sure.
  • s

    some-airline-73512

    12/15/2022, 1:11 PM
    I recorded a short video: Real-world application of HTMX and how I'm building a relatively complex web app with it.

    https://youtu.be/JE3zQpEAaxk▾

    If you have questions I'm here to help
  • b

    blue-gold-89534

    12/15/2022, 4:00 PM
    quick question: can the
    every
    interval be reduced by factor 10?
    Copy code
    html
    <div hx-get="/latest_updates" hx-trigger="every 0.1s">
      Nothing Yet!
    </div>
    like this?
  • m

    mysterious-toddler-20573

    12/15/2022, 4:05 PM
    you can use
    ms
    as an ending
  • m

    mysterious-toddler-20573

    12/15/2022, 4:05 PM
    although polling every 100ms would be unusual, I would probably look at SSE or WebSockets for something updated that frequently
  • e

    echoing-action-55459

    12/15/2022, 9:05 PM
    Is it possible to pass a JSON body along with
    hx-post
    through an attribute? Or do I have to make it a form to pass data?
  • m

    mysterious-toddler-20573

    12/15/2022, 9:35 PM
    https://htmx.org/extensions/json-enc/
  • m

    mammoth-family-48524

    12/15/2022, 9:54 PM
    I’m going to start putting all these questions and answers on StackOverflow. I’ll have so much karma 🤤
  • m

    mammoth-family-48524

    12/15/2022, 9:56 PM
    This could be me! https://stackoverflow.com/questions/586182/how-to-insert-an-item-into-an-array-at-a-specific-index-javascript 4000 upvotes!
  • l

    late-king-98305

    12/15/2022, 10:13 PM
    I'm headed out for family vacation - I may pop in here on occasion, but who knows. "at" me if you need anything, and I'll see it when I'm on. Merry Christmas, you happy band of Carson's Internet friends!
  • m

    mammoth-family-48524

    12/15/2022, 11:09 PM
    > Happy Band of Carson’s Internet Friends ❤️
  • j

    jolly-motorcycle-88169

    12/16/2022, 5:44 AM
    hello, is htmx able to do a morph that deletes content selectively?
  • j

    jolly-motorcycle-88169

    12/16/2022, 8:41 AM
    sorry found it, hx-swap-oob:delete would let it work
  • a

    abundant-spring-38265

    12/16/2022, 1:25 PM
    hey guys, how would one create a dropdown from an API endpoint (JSON data) using hx-get? 😮
  • a

    abundant-spring-38265

    12/16/2022, 1:26 PM
    e.g, i'll have a list of objects like so: https://virtserver.swaggerhub.com/paulo882/TestRunner/1.0.0/device
  • a

    abundant-spring-38265

    12/16/2022, 1:26 PM
    and I'd like to render device ID's in the dropdown list
  • a

    abundant-spring-38265

    12/16/2022, 1:30 PM
    Copy code
    <select class="form-select form-select-sm" name="device_id" hx-get="https://virtserver.swaggerhub.com/paulo882/TestRunner/1.0.0/device"
                                hx-select="#device_list">
                                <option selected disabled>Select Device</option>
                                <option name="device_list"></option>
                            </select>
  • a

    abundant-spring-38265

    12/16/2022, 1:31 PM
    This "kind of works" i.e i can see HTTP Get request go out but i'm struggling to figure out how to access element by key and also whether it loops over elements by default?
  • r

    ripe-action-67367

    12/16/2022, 1:47 PM
    Normally you would make a request to JSON endpoint on your backend and render it into your select tag there. You client then would not make any additional requests. If you, however, have to do that from the browser, you have some options
  • a

    abundant-spring-38265

    12/16/2022, 1:48 PM
    😮
1...950951952...1146Latest