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

    hallowed-pillow-66838

    03/06/2023, 10:12 AM
    Hey guys, I need a help with htmx. Is it fine to write my question here?
  • s

    stocky-dentist-80693

    03/06/2023, 10:18 AM
    Generally, yes ๐Ÿ™‚ If the issue is very specific to your backend stack only, you might get a more tailored reply in its dedicated channel (if one exists).
  • h

    hallowed-pillow-66838

    03/06/2023, 10:20 AM
    Not that specific I guess, thanks! So I have div with the elements inside and hx-get attribute placed on this div as well. Can I make an exclusion for one of the elements inside this div so it ignore hx-get?
  • s

    stocky-dentist-80693

    03/06/2023, 10:22 AM
    Yes, you should be able to use
    hx-disinherit
    for that - https://htmx.org/attributes/hx-disinherit/
  • h

    hallowed-pillow-66838

    03/06/2023, 10:22 AM
    I tried hx-disable, hx-preserve, hx-disinherit but they won't do the thing
  • s

    stocky-dentist-80693

    03/06/2023, 10:22 AM
    Hm ๐Ÿค”
  • h

    hallowed-pillow-66838

    03/06/2023, 10:22 AM
    oh, maybe I'm doing something wrong, let me try again
  • s

    stocky-dentist-80693

    03/06/2023, 10:24 AM
    It sounds like you might need
    hx-disinherit="hx-get"
    , at the very least, on your child elements inside the div.
  • h

    hallowed-pillow-66838

    03/06/2023, 10:30 AM
    I had the same logic here but it's not working the way I expect, here's a code
  • s

    stocky-dentist-80693

    03/06/2023, 10:33 AM
    What do you expect to happen vs. what IS happening?
  • h

    hallowed-pillow-66838

    03/06/2023, 10:35 AM
    When I click #link element inside of the div I get the call from the divs hx-get which I do not want to get
  • s

    stocky-dentist-80693

    03/06/2023, 10:36 AM
    Hmm, OK. Does
    hx-disinherit="*"
    work?
  • h

    hallowed-pillow-66838

    03/06/2023, 10:37 AM
    nope
  • s

    stocky-dentist-80693

    03/06/2023, 10:39 AM
    Is that attribute definitely present in the generated markup?
  • h

    hallowed-pillow-66838

    03/06/2023, 10:40 AM
    The one I click, yes, for sure. I'll try placing it above the if statement to see if that works
    s
    b
    • 3
    • 40
  • c

    calm-parrot-34414

    03/06/2023, 11:02 AM
    thats my point, many of you are ok with tailwind which touches your css but not if it would extract out your js. This would be really simple nothing hard to understand or learn, you also don't need to touch your build infra, just give the compiler the path where to put the JS and done.
  • h

    hallowed-pillow-66838

    03/06/2023, 12:04 PM
    Another issue I have with htmx is that I want only one hx-get issue be active at one time. For example: I click element with hx-get attr and get what I ask for. When I click another element with hx-get attr as well - I want the previously opened one to be closed but I get two of the opened ones instead. My best pick was to use hx-sync="this:replace" but this doesn't work. I opened up a thread on stackoverflow 10 days with the code to be more specific: https://stackoverflow.com/questions/75550355/replace-hx-get-with-the-next-hx-get-request
  • m

    mysterious-toddler-20573

    03/06/2023, 12:34 PM
    both also share "locality of behavior": https://htmx.org/essays/locality-of-behaviour/
  • m

    mysterious-toddler-20573

    03/06/2023, 12:38 PM
    seems like this is probably the line causing the issue: https://github.com/bigskysoftware/htmx/blob/5de968e933137af970644be1672a4b6eff60dc5d/src/htmx.js#L3165
  • m

    mysterious-toddler-20573

    03/06/2023, 12:38 PM
    maybe we should put a try/catch around that?
  • m

    mysterious-toddler-20573

    03/06/2023, 12:38 PM
    it sounds like you want to use hx-sync, but you need to have all the requests synchronizing using the same element
  • m

    mysterious-toddler-20573

    03/06/2023, 12:39 PM
    hx-sync uses a DOM element as a synchronization point, so if you want to coordinate requests from two elements, they need to point to the same DOM element.
  • h

    hallowed-pillow-66838

    03/06/2023, 12:54 PM
    Sound like impossible in my case or at least I can not see that possible because I have multiple '#projects' coming from a 'for loop'. That's why I've been trying to stick with logic to cancel every previous hx-get request in favor of the future one. Is that achievable?
  • m

    mysterious-toddler-20573

    03/06/2023, 12:55 PM
    Can you put an hx-sync on a parent element of all the elements making requests?
  • h

    hallowed-pillow-66838

    03/06/2023, 12:55 PM
    Sure, will try now
  • m

    mysterious-toddler-20573

    03/06/2023, 12:56 PM
    Stick a
    hx-sync="this:replace"
    on a parent element of all the elements you want synchronized
  • m

    mysterious-toddler-20573

    03/06/2023, 12:56 PM
    hx-sync should be inherited
  • m

    mysterious-toddler-20573

    03/06/2023, 12:57 PM
    and the children should all use that parent element to synchronize requests
  • m

    mysterious-toddler-20573

    03/06/2023, 12:57 PM
    https://htmx.org/attributes/hx-sync/
  • h

    hallowed-pillow-66838

    03/06/2023, 1:18 PM
    I tried that, doesn't work as I expect it. The problem is related to a 'for loop'. Because of this loop I'm having multiple 'projects' listed on the page while there's only one '#project' in the html itself. If I use hx-sync="this:replace" on the parent element - replace is coming instead of all 'projects', not a particular one I'm trying to change. A simplified version of that loop is on the screenshot.
1...105710581059...1146Latest