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

    mysterious-toddler-20573

    10/07/2022, 1:38 PM
    at some point, I'm sure we are going to write a sloppy JSON parser πŸ˜‘
  • m

    mysterious-toddler-20573

    10/07/2022, 1:38 PM
    can we see your HTML?
  • e

    echoing-dress-67727

    10/07/2022, 1:42 PM
    I don't have turbolinks or hotwire in my app, so it's not those. I can't tell from the network tab where the request is coming from. There's nothing under the "Initiator" tab, just "This request has no initiator data." Does that mean it's not coming from JS?
  • m

    mysterious-toddler-20573

    10/07/2022, 1:43 PM
    it sounds like for some reason the request isn't being `preventDefault`'ed
  • m

    mysterious-toddler-20573

    10/07/2022, 1:43 PM
    can you debug it w/ the uncompressed version of htmx and see if that line gets hit?
  • h

    happy-pillow-29003

    10/07/2022, 1:45 PM
    I got it working with something like this:
    Copy code
    <li><label for="id_events_9"><input type="checkbox" name="events" value="102" hx-get="/participations/export/" hx-include="input[name="events"]" hx-target="#days-list" hx-trigger="change" id="id_events_9" class="field field--checkbox">
    Event 1</label>
    </li>
    <li><label for="id_events_10"><input type="checkbox" name="events" value="98" hx-get="/participations/export/" hx-include="input[name="events"]" hx-target="#days-list" hx-trigger="change" id="id_events_10" class="field field--checkbox">
    Event 2</label>
    </li>
    But then I added
    load
    to the trigger and it triggered 50 requests on page load πŸ˜… I ended up putting the
    hx
    attributes on the parent element:
    Copy code
    <div hx-get="/participations/export/" hx-include="input[name='events']" hx-trigger="load, change from:input[name='events']" hx-target="#days-list">
    ... all the <input name="events"> here
    </div>
    It seems to be working fine, but maybe there’s a better way to do it?
  • e

    echoing-dress-67727

    10/07/2022, 1:49 PM
    I just did that and it does hit that line. When it gets there, the
    POST
    hasn't fired in the network tab. Then when I hit continue, the
    PATCH
    goes out, then a moment later, the
    POST
    goes out too. There's a very short delay between them. But the
    PATCH
    definitely hasn't resolved yet when the
    POST
    goes out, so it can't be anything to do with the response of that request
  • e

    echoing-dress-67727

    10/07/2022, 2:11 PM
    Ah, I think I figured it out. I've got some custom JS that seems to be doing
    form.submit()
    , which skips the
    submit
    event πŸ™„
  • m

    mysterious-toddler-20573

    10/07/2022, 2:17 PM
    Was going to say: feels like some scripting messing with us πŸ˜€
  • s

    sparse-psychiatrist-6723

    10/07/2022, 2:23 PM
    Hello, new htmx clojure developer here. I am implementing tabs on a page exactly like the HATEOAS example from the htmx site. The content of each tab consists of input fields and a Save button to post the fields to the server. I want to prevent the user going to a different tab if the current tab has unsaved changes. Is there a hypermedia pattern I may be not seeing to do that? Or, am I assuming correctly, that I will need to sprinkle in some scripting to prevent a change of tab if there are unsaved changes.
  • f

    freezing-waitress-26396

    10/07/2022, 2:30 PM
    Look at how https://htmx.org/examples/edit-row/ shows an example of
    halt
    and
    trigger
    with hyperscript where you can prevent default behavior if a certain condition is met
  • f

    freezing-waitress-26396

    10/07/2022, 2:32 PM
    you don't have to use Swal here, but for example adding a class to the switched tab parent element (or something, not the input itself) whenever a change happens on an input field, then clicking on a tab would check if said class exists then
    halt
    , preventing a tab switch after changing something. Of course, whenever you save, you remove the respective class again.
  • s

    sparse-psychiatrist-6723

    10/07/2022, 2:34 PM
    thank you
  • m

    mysterious-toddler-20573

    10/07/2022, 3:46 PM
    that looks a little elaborate, but not insane
  • g

    green-activity-6102

    10/07/2022, 4:06 PM
    is there a way to swap the new HTML into multiple nodes on the page if the selector matches both? (eg a class selector)
  • g

    green-activity-6102

    10/07/2022, 4:06 PM
    seems like the default behavior is just to swap the top-most one in the DOM
  • m

    mysterious-toddler-20573

    10/07/2022, 4:12 PM
    right now, no, you'd need to use an oob swap to target multiple elements unfortunately
  • g

    green-activity-6102

    10/07/2022, 4:13 PM
    shoot... any plans for that? i've got the same toggle in multiple spots on my page -- when i toggle it in either place it would be great to update it on both
  • g

    green-activity-6102

    10/07/2022, 4:13 PM
    oob swap is kinda tough in this case because the 2 elements are literally identical (rendered from the same partial template)
  • m

    mysterious-toddler-20573

    10/07/2022, 4:14 PM
    I was hoping to add it in htmx 2, since it would technically be a breaking change
  • m

    mysterious-toddler-20573

    10/07/2022, 4:14 PM
    in the meantime, we could build an extension that does this I think
  • g

    green-activity-6102

    10/07/2022, 4:14 PM
    i wonder if you could introduce a flag in hx-target or hx-swap to turn this behavior on optionally, maintain backwards compat
  • g

    green-activity-6102

    10/07/2022, 4:15 PM
    something like
    hx-target=".element:all"
  • m

    mysterious-toddler-20573

    10/07/2022, 4:15 PM
    that's a good idea
  • m

    mysterious-toddler-20573

    10/07/2022, 4:15 PM
    would need to think about the syntax
  • g

    green-activity-6102

    10/07/2022, 4:17 PM
    meantime i'll look at writing a little extension to help me, thanks πŸ‘
  • g

    green-activity-6102

    10/07/2022, 4:17 PM
    never written an htmx extension, if you've got pointers on where to start on this particular one i'm all ears
  • g

    green-activity-6102

    10/07/2022, 4:17 PM
    reading the extension docs and examples now
  • b

    brainy-ice-92385

    10/07/2022, 4:28 PM
    An htmx extension seems like overkill. I would just add a handler for the "afterSwap" event on one of your targets, then clone it to the other place. Just to say if the htmx extension part feel daunting, you don't need it
  • g

    green-activity-6102

    10/07/2022, 4:29 PM
    honestly extensions look way easy to implement and this functionality may be useful in other places on my project so i'll give that a go first -- probably end up using afterSwap inside the extension actually
1...846847848...1146Latest