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

    mysterious-toddler-20573

    10/28/2022, 2:48 AM
    yep, this is the direction I'm heading right now
  • m

    mysterious-toddler-20573

    10/28/2022, 2:49 AM
    Still thinking about script elements, and re-evaluating them
  • m

    mysterious-toddler-20573

    10/28/2022, 2:49 AM
    but I thing this is the right direction
  • b

    brainy-ice-92385

    10/28/2022, 6:59 AM
    Little pattern enhancing htmx with Hyperscript: The feature is a text input which saves automatically while the user types. The API response is a content change to the indicator below, which lets the user know the status of the save. The user should be reassured that their changes are being recorded as soon as they make a change. Of course, I don't want to send a request for every single keypress. It can wait a moment until the user types a full thought. Enter `hx-trigger`'s
    delay
    syntax, which debounces the given event by the given time.
    Copy code
    <div
        hx-trigger="input delay:500ms"
        hx-swap="innerHTML"
        hx-post="/api/setter"
        hx-target="[data-save-indicator]"
        hx-indicator="[data-save-indicator]"
        _="on input tell the next <.htmx-indicator />
                    add .htmx-request to yourself
                    put 'Saving...' into yourself"
    >
        <label>
            Write your input!
            <input type="text" name="value" />
        </label>
    </div>
    <div class="htmx-indicator" data-save-indicator>Saving...</div>
    I wanted to use
    hx-indicator
    but
    hx-indicator
    adds the
    htmx-request
    class to the given CSS selector when the request begins, after the delay. This is too late! I want to let users know their info is in safe hands as soon as possible. So, I take things into my own hands with hyperscript to add the class myself immediately to show the indicator. This doesn't mess with htmx's use of that class at all. I also reset the content of the indicator, since a prior API response could have changed it.
  • b

    boundless-vase-80440

    10/28/2022, 10:57 AM
    I work with a customer where they decided after much deliberation that the best http code to return when you query for something and there are no results is... 404 Not Found. I hate "REST".
  • p

    prehistoric-wolf-75047

    10/28/2022, 11:02 AM
    The event modifier
    throttle
    doesn't seem to work for me. On an element like this
    <input type="number" hx-post="" hx-trigger="change throttle:10s">
    the POST request ist sent immediately. Do I need to configure it differently?
  • p

    prehistoric-wolf-75047

    10/28/2022, 11:34 AM
    I obviously misunderstood how
    throttle
    works. The request is expected to fire immediately but all subsequent requests within the declared time window are discarded. Does anybody else find the wording in the docs unprecise?
  • r

    ripe-action-67367

    10/28/2022, 12:15 PM
    https://htmx.org/docs/#trigger-modifiers not sure what wording you're referring to > throttle: - wait the given amount of time (e.g. 1s) before issuing the request. Unlike delay if a new event occurs before the time limit is hit the event will be discarded, so the request will trigger at the end of the time period.
  • p

    prehistoric-wolf-75047

    10/28/2022, 2:27 PM
    There's also this one: https://htmx.org/attributes/hx-trigger/ >
    throttle:<timing declaration>
    - a throttle will occur before an event triggers a request. If the event is seen again before the delay completes it is ignored, the element will trigger at the end of the delay. Both state that
    <timing>
    introduces a delay before the request is fired and my observation is that the request is sent immediately.
  • p

    prehistoric-wolf-75047

    10/28/2022, 2:32 PM
    With `throttle:3s`:
    Click…Request #1…1s…2s…Click (discarded)…3s…Click…Request #2
    vs.
    Click…1s…2s…Click (discarded)…3s…Request
    The latter is how I understand how it should work. But maybe that's just because I'm not a native speaker.
  • b

    bitter-machine-55943

    10/28/2022, 3:08 PM
    I like decorators and mixins
  • b

    bitter-machine-55943

    10/28/2022, 3:08 PM
    Don’t ban me
  • e

    echoing-action-55459

    10/28/2022, 3:48 PM
    I do to but until they're standardized I don't wanna use them in typescript
  • e

    echoing-action-55459

    10/28/2022, 3:53 PM
    Has there been any thought into breaking down HTMX into more plugins? Right now dependency size is a huge topic, like fresh boasting zero kb js. Curious if we could bundle HTMX like tailwind, we check to see what attributes are used and build a bundle specific to the js sent down or entire project. https://twitter.com/thomasreggi/status/1583481276220133377
  • m

    mysterious-toddler-20573

    10/28/2022, 3:56 PM
    #974086000307499028
  • m

    mysterious-toddler-20573

    10/28/2022, 3:56 PM
    well
  • m

    mysterious-toddler-20573

    10/28/2022, 3:56 PM
    maybe not
  • m

    mysterious-toddler-20573

    10/28/2022, 3:57 PM
    i dunno, I am a boomer-in-spirit and this discord stuff is frightening and confusing to me
  • s

    silly-soccer-20915

    10/28/2022, 4:10 PM
    hi everyone! is there a way to stop htmx from swapping the title tag after an hx-get??
  • m

    mysterious-toddler-20573

    10/28/2022, 4:18 PM
    Not currently, but there should be
  • s

    silly-soccer-20915

    10/28/2022, 4:22 PM
    i wonder why i had never gotten into this topic 😮 loading another page's content into the one where the request is made
  • m

    mysterious-toddler-20573

    10/28/2022, 4:23 PM
    @echoing-action-55459 @acceptable-spring-94420 just pushed up what I think is a good compromise on the head support. We now treat boosts and non-boosts differently, (merge vs. append, based on @echoing-action-55459 's suggestion) with the ability to override w/ an hx-head annotation. You can also keep a specific element in the head permanently by putting an
    hx-preserve
    attribute on it, and have it re-execute by placing an
    hx-head="re-eval"
    on it.
  • m

    mysterious-toddler-20573

    10/28/2022, 4:24 PM
    @hundreds-camera-24900 I think you were asking about better boost detection in events, and we now include a top level
    boosted
    boolean in the detail for both pre-request and post-request events triggered by htmx
  • e

    echoing-action-55459

    10/28/2022, 4:24 PM
    link?
  • m

    mysterious-toddler-20573

    10/28/2022, 4:25 PM
    currently in dev
  • m

    mysterious-toddler-20573

    10/28/2022, 4:25 PM
    https://github.com/bigskysoftware/htmx/blob/dev/src/htmx.js
  • m

    mysterious-toddler-20573

    10/28/2022, 4:25 PM
    https://github.com/bigskysoftware/htmx/blob/dev/src/htmx.js
  • m

    mysterious-toddler-20573

    10/28/2022, 4:25 PM
    would love a code review if you have time
  • m

    mysterious-toddler-20573

    10/28/2022, 4:37 PM
    https://twitter.com/GrugBrainedDev/status/1586033905555017728
  • s

    silly-soccer-20915

    10/28/2022, 4:41 PM
    Avoid swapping the title workaround:
    Copy code
    js
    htmx.defineExtension('prevent-title-update', {
        handleSwap: function(swapStyle, target, fragment, settleInfo){
          settleInfo.title = document.title;
        }
    });
1...879880881...1146Latest