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

    ripe-action-67367

    01/16/2023, 5:31 PM
    Do you send just a full page and select oob elements from it?
  • r

    ripe-action-67367

    01/16/2023, 5:37 PM
    if yes, I would say, that you should send these elements as normal oob elements from the server, instead of specifying it in the form
  • r

    ripe-action-67367

    01/16/2023, 5:37 PM
    or, just swap an entire page
  • m

    mysterious-toddler-20573

    01/16/2023, 5:40 PM
    yep, what are you trying to achieve?
  • s

    some-airline-73512

    01/16/2023, 6:00 PM
    I have a page, on any click I want to swap these elements (in red)
  • s

    some-airline-73512

    01/16/2023, 6:01 PM
    It's working pretty well, no problems. But I thought maybe having this large select-oob is too much.
  • s

    some-airline-73512

    01/16/2023, 6:04 PM
    Some clicks require less swap, some more. When I was just starting the project, I was writing custom select-oob for every button. Over time I saw that it's very error-prone. I have to remember to keep select-oob in sync with what the server actually returns. So to improve code robustness, I came up with this approach: - Write single select-oob at the top, mentioning everything that I may want to swap on the page. - Send specific pieces from the server depending on the endpoint. That way the code is very robust, I don't have to worry about writing select-oob for every fking button.
    Copy code
    html
    <form hx-select-oob="{{const.stTableSwapOob}}" script="init noEnter(me)">
  • s

    some-airline-73512

    01/16/2023, 6:06 PM
    So this is just an annoyance, nothing more.
  • s

    some-airline-73512

    01/16/2023, 6:08 PM
    I just got a real problem, when using
    morph:outerHTML
    , the swapped element just disappears. When using regular
    outerHTML
    , it works well. So I'm debugging htmx source for few hours already, I found this line that removes the node:
    Copy code
    js
    oobElement.parentNode.removeChild(oobElement);
    I'm not sure what is the contract between morph extension and the htmx core. Seems like extension is supposed to insert the node into the DOM, but I don't know how to fix this. Anyone can show me the direction how it should work?
  • r

    ripe-action-67367

    01/16/2023, 6:12 PM
    My thinking here is, your server already knows which elements should be swapped
    {{const.stTableSwapOob}}
    , and it also has all the data that's gonna be swapped. Instead of having it selected by
    hx-select-oob
    on the page, I would just use knowledge of the server and respond
    Copy code
    html
    <div id="st-colors-search" hx-swap-oob="true">...</div>
    <div id="st-impressionss-search" hx-swap-oob="true">...</div>
    <div id="st-cpcs-search" hx-swap-oob="true">...</div>
    ...
    this way you don't need to care about server response in your client-side selector at all
  • s

    some-airline-73512

    01/16/2023, 6:13 PM
    Hm, I didn't know that I could just do
    hx-swap-oob="true"
  • s

    some-airline-73512

    01/16/2023, 6:14 PM
    That's cool, thank you @ripe-action-67367
  • r

    ripe-action-67367

    01/16/2023, 6:14 PM
    The only thing i'm not sure about is potential target errors
  • s

    some-airline-73512

    01/16/2023, 6:14 PM
    Though it would require the templates to know whether they should add
    hx-swap-oob
    attribute or not
  • r

    ripe-action-67367

    01/16/2023, 6:15 PM
    Like, I don't remember what the behavior is with OOB
  • r

    ripe-action-67367

    01/16/2023, 6:15 PM
    May require testing
  • s

    some-airline-73512

    01/16/2023, 6:15 PM
    Yeah I'm trying to make it work now, getting frustrated a bit
  • t

    tall-dinner-62086

    01/16/2023, 6:17 PM
    The template should know which fragments to render, and the ones that should be swapped OOB should probably always set
    hx-swap-oob="true"
  • r

    ripe-action-67367

    01/16/2023, 6:18 PM
    morphing problems sounds like something that needs additional investigating
  • s

    some-airline-73512

    01/16/2023, 6:20 PM
    After applying hx-swap-oob="true" as you just said, it works!! 🔥
  • s

    some-airline-73512

    01/16/2023, 6:20 PM
    So instead of
    hx-select-oob
    I have to use
    hx-swap-oob
    with morphing
  • s

    some-airline-73512

    01/16/2023, 6:21 PM
    Fk, I need to write my own htmx to understand how it works
  • s

    some-airline-73512

    01/16/2023, 6:21 PM
    Very frustrating when I don't quite know who is wrong: is it the core wrong or extension?
  • r

    ripe-action-67367

    01/16/2023, 6:22 PM
    I believe, hx-select-oob is relatively recent addition
  • r

    ripe-action-67367

    01/16/2023, 6:22 PM
    So I think it's just a bug
  • r

    ripe-action-67367

    01/16/2023, 6:23 PM
    htmx 2.0 is on the horizon, sooooooooo
  • s

    some-airline-73512

    01/16/2023, 6:26 PM
    I'm all in to help
  • s

    some-airline-73512

    01/16/2023, 6:26 PM
    Because I want to own my dependencies. Now I feel little horrified. If I stumble on bug, which I should be able to fix in 5 mins, and I waste 2 hours on it with zero progress
  • s

    some-airline-73512

    01/16/2023, 6:29 PM
    For 2.0 I would vote for zero inheritance. I want to see the full description of behavior on a single node. Now I need to scan everything to the top with my eyes. And my eyes are not compiler.
  • s

    some-airline-73512

    01/16/2023, 6:30 PM
    Inheritance is one of the ways to achieve DRY, I understand that. But it's not the only way. We can just use a variable in template. Done.
1...987988989...1146Latest