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

    bumpy-pilot-80789

    09/04/2022, 6:25 PM
    I believe the registration and spot to listen are all fine and dandy after some testing there, indeed
  • b

    bumpy-pilot-80789

    09/04/2022, 6:25 PM
    but it could be consumed before, perhaps, indeed
  • b

    bumpy-pilot-80789

    09/04/2022, 6:25 PM
    jQuery?
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:25 PM
    One more shot in the dark....
  • b

    bumpy-pilot-80789

    09/04/2022, 6:26 PM
    shoot!
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:27 PM
    After you post the form, does it disappear from the screen? The default behavior would be for htmx to replace the existing page with empty content. Depending on where you've defined the event handlers, this might be nuking that code.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:27 PM
    nope, it doesn't, thanks to the 204
  • b

    bumpy-pilot-80789

    09/04/2022, 6:27 PM
    if I make it a 200, then it is replaced by whatever my response provides
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:28 PM
    Ok, so nothing is getting removed from your web page. Cool. I was thinking maybe using
    hx-swap="none"
    might help prevent this, but it's probably unnecessary code.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:28 PM
    yes, I read in the docs that this is what the 204 is for
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:29 PM
    Yep. Good.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:29 PM
    I could replace the form with the thank you modal, but I understand that would force me to put the HTML code of the modal in my backend code right? I want to avoid that
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:30 PM
    Yeah. That *might*/*should* work. But I try to avoid that too. It's easier to keep those things on separate parts of the server.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:31 PM
    yes, and I'm using this backend for multiple forms all having different UX, to
  • b

    bumpy-pilot-80789

    09/04/2022, 6:32 PM
    so, if I understand correctly, my use case for HTMX is valid and the implementation seems fine
  • b

    bumpy-pilot-80789

    09/04/2022, 6:32 PM
    time to debug some more then
  • b

    bumpy-pilot-80789

    09/04/2022, 6:32 PM
    let me try to set this up with some minimal HTML
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:32 PM
    Is there a way that you could post your front-end code?
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:32 PM
    Yes. This.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:32 PM
    yes, there certainly is
  • b

    bumpy-pilot-80789

    09/04/2022, 6:33 PM
    can I DM you?
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:33 PM
    Of course. It's lunch time here in Denver, so I'll be in and out for a bit. But I'm happy to dig in deeper with you 🙂
  • b

    bumpy-pilot-80789

    09/04/2022, 6:33 PM
    hehe; greetings from a hot summer's evening in Belgium 🙂
  • b

    bumpy-pilot-80789

    09/04/2022, 6:34 PM
    (publishing now)
  • l

    late-king-98305

    09/04/2022, 7:32 PM
    Is there something in particular you're struggling with? One of the mind-shifts with htmx comes in the form of the target for your
    form
    - where you normally would do a POST-redirect-GET, you can just target the resulting area of your page, then use
    HX-Retarget
    if there's an error.
  • b

    bumpy-pilot-80789

    09/04/2022, 7:39 PM
    hey, thanks for taking an interest interest in this too, @late-king-98305
  • b

    bumpy-pilot-80789

    09/04/2022, 7:42 PM
    my plan is as follows: - hx-post the form to a backend - have the backend reply with an empty response - have the response have status code 204 in case of success, and status code 404 else - make the frontend display a modal in either case - set the HX-Trigger header to select between the two modals ('thank you' or 'something went wrong')
  • b

    bumpy-pilot-80789

    09/04/2022, 7:44 PM
    I don't think I can use hx-retarget, as I'm never sending a response body from backend to frontend, right?
  • b

    bumpy-pilot-80789

    09/04/2022, 7:45 PM
    what I'm struggling with is that I simply don't seem to be getting an event dispatched with the HX-Trigger response header
  • b

    blue-ghost-19146

    09/04/2022, 7:55 PM
    @bumpy-pilot-80789 I’m not too familiar with jQuery but in htmx you would listen for an HX-Trigger event like
    hx-trigger=“myEvent from:body”
    . So I would assume that the event listener needs to be on the body. You may already be listening for it there, but I thought it was worth saying just in case!
1...816817818...1146Latest