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

    magnificent-camera-86904

    03/09/2023, 7:03 AM
    Thanks. I am trying,
    hx-trigger="keyup[enterKey]"
    But no request is sent.
  • r

    ripe-action-67367

    03/09/2023, 7:05 AM
    Is enterKey a property of keyup event object?
  • r

    ripe-action-67367

    03/09/2023, 7:06 AM
    You provided a sample of JS code you would use to implement that. Take the condition from the if statement and put it into square brackets
  • m

    magnificent-camera-86904

    03/09/2023, 7:10 AM
    Nice, that worked! I am still super confused on what is happening here. I see in the docs it says: > You may also apply trigger filters by using square brackets after the event name, enclosing a javascript expression that will be evaluated. If the expression evaluates to true the event will trigger, otherwise it will not. I didn't realize
    hx-trigger="click[ctrlKey]"
    ctrlKey qualifies as a JavaScript expression. And if it is, I am not sure why
    hx-trigger="keyup[enterKey]"
    didn't work for me. Anyway, here is the final code snippet:
    Copy code
    js
    hx-trigger="keyup[key === 'Enter' && !shiftKey]"
  • r

    ripe-action-67367

    03/09/2023, 7:11 AM
    it doesn't qualify as JS
  • r

    ripe-action-67367

    03/09/2023, 7:11 AM
    JS expression is what's in the square brackets like
    event[JS expression]
  • r

    ripe-action-67367

    03/09/2023, 7:12 AM
    any variables from this expression are resolved against the event object, then the global scope
  • r

    ripe-action-67367

    03/09/2023, 7:12 AM
    ctrlKey is part of the spec and, as a result, present in the event object and resolved by htmx. enterKey is not
  • r

    ripe-action-67367

    03/09/2023, 7:13 AM
    https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/ctrlKey
  • m

    magnificent-camera-86904

    03/09/2023, 7:14 AM
    Ah, thank you. I didn't realize that keys like ctrlKey, altKey and others get their own property, but enterKey doesn't. Good to know!
  • s

    shy-knife-59740

    03/09/2023, 2:00 PM
    I havent found any docs on this but how would i load an element only a single time when the page loads?
    Copy code
    html
    <div hx-get="/posts" hx-target="#test" hx-trigger="load once">postlist:</div>
    this sadly doesent load, it loads infinetly
  • s

    shy-knife-59740

    03/09/2023, 2:16 PM
    im looking for something that will execute once on an event like:
    DOMContentLoaded
    or
    window.onload
  • g

    green-addition-61042

    03/09/2023, 2:17 PM
    can we haz 1.8.6? 😇 https://github.com/bigskysoftware/htmx/releases
  • r

    ripe-action-67367

    03/09/2023, 2:19 PM
    load event should be firing once already. What do you mean by "loads indefinitely"?
  • r

    ripe-action-67367

    03/09/2023, 2:31 PM
    Does
    /posts
    page contain its own hx-get with hx-trigger=load?
  • s

    shy-knife-59740

    03/09/2023, 2:31 PM
    nope just returns a jinja template
  • s

    shy-knife-59740

    03/09/2023, 2:31 PM
    but
  • r

    ripe-action-67367

    03/09/2023, 2:32 PM
    Could you show the response?
  • s

    shy-knife-59740

    03/09/2023, 2:32 PM
    the template extends base,html which im using for the htmx part
  • s

    shy-knife-59740

    03/09/2023, 2:33 PM
    oh goodness, i just realized what i said
  • s

    shy-knife-59740

    03/09/2023, 2:33 PM
    it was creating an infinite loop hahah
  • r

    ripe-action-67367

    03/09/2023, 2:33 PM
    basically yes
  • r

    ripe-action-67367

    03/09/2023, 2:34 PM
    I would rework the page, so that posts can be loaded without lazy loading attributes
  • r

    ripe-action-67367

    03/09/2023, 2:35 PM
    you could also take a look at hx-select attribute https://htmx.org/attributes/hx-select/
  • s

    shy-knife-59740

    03/09/2023, 2:35 PM
    like loading the jinja template instead?
  • r

    ripe-action-67367

    03/09/2023, 2:35 PM
    Yes, without the base template
  • s

    shy-knife-59740

    03/09/2023, 2:36 PM
    the way im doing it is basically like this: - if there is a
    hx-request
    header, it returns a jinja template - if there is no
    hx-request
    header, it simply returns json with all the data
  • s

    shy-knife-59740

    03/09/2023, 2:36 PM
    so that later i can add some query params to that endpoint
  • s

    shy-knife-59740

    03/09/2023, 2:38 PM
    how is different from hx-target and hx-swap together?
  • r

    ripe-action-67367

    03/09/2023, 2:39 PM
    hx-target defines where to put the response. hx-swap defines how to put the response (overwrite, append, outer/inner). hx-select allows to define, which part of the response to use
1...106210631064...1146Latest