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

    adventurous-ocean-93733

    05/05/2023, 4:07 PM
    > "Title needs (2011). Not because that's when it was written but because that's when this technique was the future." Fair play, that's a good one. You gotta take that on the chin.
  • m

    mysterious-toddler-20573

    05/05/2023, 4:10 PM
    🙂
  • w

    witty-account-33479

    05/05/2023, 4:17 PM
    Greetings, grugs! I am doing my first htmx project and have only a little frontend js experience. I have a multi-stage page in which live search in the first form makes an htmx request that returns a second form with a bunch of autofilled/dynamic values to choose from. Among these is a set of input checkboxes inside a span with id
    #topics
    . In this span's
    onchange
    attribute I call a js validation function. I also need to call the function once when the elements arrive. I don't think it matters much if it's on "load" or "afterSettle" or some other point. The easiest way I could see to do this was to handle this was with a global htmx.onLoad listener:
    Copy code
    addEventListener('DOMContentLoaded', ()=> {
        htmx.onLoad((el)=> {
          if ((topics = el.querySelector('#topics'))) {
            validate_topics_checkboxes(el)
          }
        });
      });
    Another thing I tried was to add an inline script element alongside the span in the htmx response. Surprisingly this caused the function to be called twice. In my case it's not terrible to call validation twice, but in general this seems like a bug or at least undesirable/unsupported behavior. Should I file an issue for this? Ultimately, my question is whether there is a way to do this with better locality to the DOM element. In my ideal world onload would work on all elements and I could just write
    <span id="topics" onload="validate_topics_checkboxes()" onchange="validate_topics_checkboxes()">
    . Sadly that's not how onload works. From the docs I see that LoB is valued by the authors, so I wonder if this is something that has been hashed out before. Thanks in advance!
  • m

    mysterious-toddler-20573

    05/05/2023, 4:30 PM

    https://cdn.discordapp.com/attachments/725789747212976259/1104082772760465408/image.png▾

  • m

    mysterious-toddler-20573

    05/05/2023, 4:31 PM

    https://cdn.discordapp.com/attachments/725789747212976259/1104082866838708354/iu.png▾

  • r

    ripe-action-67367

    05/05/2023, 4:37 PM
    oh my god

    https://cdn.discordapp.com/attachments/725789747212976259/1104084380449783920/image.png▾

  • r

    ripe-action-67367

    05/05/2023, 4:37 PM
    OH MY GOD

    https://cdn.discordapp.com/attachments/725789747212976259/1104084424817115246/image.png▾

  • r

    ripe-action-67367

    05/05/2023, 4:38 PM
    That's it, ima make a hackernews account
  • m

    mysterious-toddler-20573

    05/05/2023, 4:44 PM
    🙂
  • m

    mysterious-toddler-20573

    05/05/2023, 4:44 PM
    rather yes, mmm, i see thank u
  • g

    great-article-50141

    05/05/2023, 4:45 PM
    Some of the comments on there are cringe, not gonna lie
  • m

    mysterious-toddler-20573

    05/05/2023, 4:45 PM
    this was a funny interaction too:

    https://cdn.discordapp.com/attachments/725789747212976259/1104086602235523099/image.png▾

  • m

    mysterious-toddler-20573

    05/05/2023, 4:46 PM
    this was on the decoupling comments
  • g

    great-article-50141

    05/05/2023, 4:46 PM
    I've been using HTMX with Laravel on a professional site, single dev. I replaced a Vue front-end that took a front-end dev 3 months to do in one, yes one, week with some extra hours. Some of these comments are so stupid compared to what I've experienced if you're willing to put some work into it.
  • g

    great-article-50141

    05/05/2023, 4:46 PM
    Ooof
  • b

    bitter-monkey-50309

    05/05/2023, 5:47 PM
    I think quite a lot of people are missing the point that htmx on it's own isn't meant to replace React, you're still allowed to use clientside JS, jQuery, Hyperscript, Alpine, whatever.js 🤦‍♂️
  • d

    dazzling-shoe-67340

    05/05/2023, 5:48 PM
    I never jumped on the JS frontend bandwagon because among other things, it meant putting my CMS of choice (ProcessWire) in the backseat and treating like it some API endpoint. And really, for what (at least for the type of stuff I do)? F that!
  • g

    gorgeous-ghost-95789

    05/05/2023, 5:53 PM
    Howdy @witty-account-33479 , Since you're dynamically loading fragments into your DOM, you may have trouble with standard HTML events like
    load
    . You may want to check out [
    hx-on
    ](https://htmx.org/attributes/hx-on/) which helps you to capture htmx events like
    htmx:load
    , etc.
  • b

    bitter-machine-55943

    05/05/2023, 6:16 PM
    https://github.com/dtao/whatever.js Hasn’t been updated in a while
  • a

    adamant-state-54102

    05/05/2023, 7:42 PM
    What is the preferred way in htmx to update parent components. To take a trivial example, say you have a TODO list with an h2 like "TODO (6)" where the six indicates the number on the list, and then you have list items that can be edited and completed (using htmx POSTs). The server response ofc correctly updates the item itself, but now the "(6)" may be incorrect. You can use an hx-trigger, and I've taken this approach, but it never felt quite right because I now encoding knowledge of dependencies within overall page compoments into the response for a single item. Another option is to just re-render the entire page, which honestly seems simplest, but at that point htmx isn't much different from an old-school, non-htmx MPA. Am I missing anything?
  • v

    victorious-artist-2344

    05/05/2023, 7:44 PM
    Remove this from the page title? 😅
  • g

    gorgeous-airport-54386

    05/05/2023, 7:45 PM
    https://htmx.org/attributes/hx-swap-oob/
  • a

    adamant-state-54102

    05/05/2023, 7:45 PM
    @victorious-artist-2344 It's not the page title, I edited to clarify.
  • v

    victorious-artist-2344

    05/05/2023, 7:46 PM
    (I’m only half serious) remove the count from the h2 😅
  • v

    victorious-artist-2344

    05/05/2023, 7:47 PM
    ➕
  • a

    adamant-state-54102

    05/05/2023, 7:48 PM
    Right, I forgot about that. But that suffers the same reservation I had about hx-trigger: "but it never felt quite right because I now encoding knowledge of dependencies within overall page compoments into the response for a single item." It starts to feel like procedural style jquery updates, just enacted using a different mechanism.
  • v

    victorious-artist-2344

    05/05/2023, 7:49 PM
    Hmm, it’s still declarative, no?
  • v

    victorious-artist-2344

    05/05/2023, 7:49 PM
    The element has a unique ID
  • v

    victorious-artist-2344

    05/05/2023, 7:53 PM
    I think if you don’t want full page reloads or some machinery to deal with the template code reuse in a good way… removing the count is a very real way to simplify this massively, at the cost of some UX polish
  • a

    adamant-state-54102

    05/05/2023, 7:53 PM
    Not in any meaningful sense, no -- the virtue of being declarative is that you can understand something without knowing the details. But now where does this dependency live? I'm looking at my page, if I want to know about this dep between these parts I have to look at the server response for updating an item (or deleting or adding one). It would be very easy to miss.
1...111211131114...1146Latest