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

    bumpy-pilot-80789

    09/04/2022, 6:08 PM
    this is the relevant backend code (Python, Flask)
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:09 PM
    Gotcha. So, something like
    HX-Trigger:form2mail
    and then
    window.addEventListener('form2mail', function() {...})
  • b

    bumpy-pilot-80789

    09/04/2022, 6:09 PM
    Copy code
    javascript
    addEventListener("form2mail", function (_e) { ... });
  • b

    bumpy-pilot-80789

    09/04/2022, 6:09 PM
    exactly
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:10 PM
    Hmmm... it should just work. Give me one minute?
  • b

    bumpy-pilot-80789

    09/04/2022, 6:10 PM
    the trigger is supposed to show a 'thank you'-modal, perhaps there's another way to fulfil my use case?
  • b

    bumpy-pilot-80789

    09/04/2022, 6:10 PM
    yes, sure, thanks a lot for taking an interest!
  • b

    bumpy-pilot-80789

    09/04/2022, 6:11 PM
    (
    Copy code
    javascript
    window.dispatchEvent(new Event('form2mail'))
    from my browser's console simply works)
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:11 PM
    There are several ways to do modals, and a lot depends on what's best for your back-end architecture. There's no reason you can't/shouldn't do it this way.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:11 PM
    ok
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:13 PM
    Ok, I'm shooting a bit in the dark, but I think the function
    addEventListener
    might default to working with the
    document
    , not the
    window
    Can you try prefixing your code with
    window.addEventListener()
    instead of just saying
    addEventListener()
    ?
  • b

    bumpy-pilot-80789

    09/04/2022, 6:15 PM
    just tried that, but no difference
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:16 PM
    shoot. Sorry.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:16 PM
    also, my linter tells me that
    window.addEventListener
    ought to be the same as simpy
    addEventListener
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:17 PM
    and (just to cover all of our bases) you can see the
    HX-Trigger
    header showing up in the browser's dev tools in the response to your HTTP Post?
  • b

    bumpy-pilot-80789

    09/04/2022, 6:17 PM
    yup
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:18 PM
    Gotcha. I wasn't sure, so it's good to eliminate weird edge cases.
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:18 PM
    ok. There should be something pretty simple that we're missing here. HX-Trigger works great for me, so we just have to find what's causing the disconnect. 🙂
  • b

    bumpy-pilot-80789

    09/04/2022, 6:19 PM
    just thinking: could it have to do anything with the 204 status code?
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:20 PM
    Hmmm.. That's a possibility and it's easy to check. Theoretically, it shouldn't matter, but maybe try making it a 200 to see?
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:20 PM
    I'm looking at the source to see what I can find..
  • b

    bumpy-pilot-80789

    09/04/2022, 6:20 PM
    hm, no, just tried it with 200 and some content, but that didn't change anything
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:22 PM
    Ok, same. It doesn't seem like a 204 should be any different from a 200.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:22 PM
    k
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:23 PM
    Hmmm.. well this is definitely not a "newbie" question.
  • b

    bumpy-pilot-80789

    09/04/2022, 6:23 PM
    oh, okay
  • b

    bumpy-pilot-80789

    09/04/2022, 6:23 PM
    oops 😄
  • b

    bumpy-pilot-80789

    09/04/2022, 6:23 PM
    I'm not new at web development, but I am only just exploring HTMX (and really liking it, so far!)
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:24 PM
    So, unless you see any other weird errors in the browser console, I'm pretty sure the event is getting fired. So, my money (all $0.00 of it) is on there being some problem with the event listener -- getting it registered correctly, listening to the right spot, or perhaps the event getting consumed by something else somewhere along the way.
  • g

    gorgeous-ghost-95789

    09/04/2022, 6:25 PM
    You did say, though, that it worked when you triggered the event straight from the console....
1...815816817...1146Latest