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

    eager-city-40681

    01/31/2023, 12:52 AM
    @late-king-98305 Thanks. You wouldn't happen to know of a document that describe, in high level terms, how htmx works under the hood. I tried setting a breakpoint on a dom element, but it was hard to follow the htmx code. I thought htat might be a good place for me to figure this out – by following how htmx resolves it's attributes and turns them into actions.
  • l

    late-king-98305

    01/31/2023, 12:54 AM
    I'd start with https://htmx.org/docs/#debugging which describes some techniques you can use. It also references loading the unminimized version; which might be easier to follow if you're wanting to dig into the internals.
  • e

    eager-city-40681

    01/31/2023, 12:54 AM
    @late-king-98305 Perfect, thanks Daniel!
  • a

    agreeable-apartment-19546

    01/31/2023, 12:56 AM
    I'm not entirely sure how to tackle this one. I have a
    <form hx-get="blah" hx-target="#content">
    inside the
    #content
    div. The API response seems to be working fine. The client gives me this :
  • l

    late-king-98305

    01/31/2023, 12:57 AM
    That unminified version should be at https://unpkg.com/htmx.org/dist/htmx.js - I don't think it's linked from the debugging docs.
  • a

    agreeable-apartment-19546

    01/31/2023, 12:57 AM
    Thanks !
  • l

    late-king-98305

    01/31/2023, 12:59 AM
    Oh - you're welcome to use that too... That was for @eager-city-40681 . In your case, I'm not sure. I would think that for even a malformed payload, it would throw a nicer error. That being said - the unminimized version would have better function names in the stack trace. 🙂
  • a

    agreeable-apartment-19546

    01/31/2023, 12:59 AM
    Yeah, the trace is a little more handy, but uh...
  • a

    agreeable-apartment-19546

    01/31/2023, 12:59 AM
    ( great coincidence having that link to the unminified stuff )
  • l

    late-king-98305

    01/31/2023, 1:00 AM
    Does your payload have any triggers or other things that would require evaluating script?
  • a

    agreeable-apartment-19546

    01/31/2023, 1:01 AM
    The
    get
    is intercepted with a pretty basic
    configRequest
    :
    Copy code
    javascript
        document.body.addEventListener("htmx:configRequest", function (event) {
            event.detail.path = "/html/maps/" + document.getElementById("callsign").value;
        });
  • l

    late-king-98305

    01/31/2023, 1:02 AM
    Do your dev tools show what's coming back from that? Since this is being thrown during the settle phase (bottom of that stack trace), you should be able to see the request and response in the Network tab.
  • a

    agreeable-apartment-19546

    01/31/2023, 1:04 AM
    The response looks just fine, at a glance. The client in the Network tab is seeing the same response as the server seems to be sending
  • a

    agreeable-apartment-19546

    01/31/2023, 1:04 AM
    I imagine having two
    script
    tags one after the other is not a problem ?
  • l

    late-king-98305

    01/31/2023, 1:04 AM
    It shouldn't be. Thinking....
  • a

    agreeable-apartment-19546

    01/31/2023, 1:04 AM
    Copy code
    html
    <div id="map_layer" class="h-96" style="border-radius: 10px;"></div>
    
    <script>
        form = document.getElementById("form_maps");
    
        document.getElementById("look_up").addEventListener("keypress", function (event) {
            if (event.key === "Enter") {
                form.submit(event);
            }
        });
    
        document.body.addEventListener("htmx:configRequest", function (event) {
            event.detail.path = "/html/maps/" + document.getElementById("callsign").value;
        });
    </script>
    
    
    
    <script>
            var map = L.map('map_layer').setView([47.67, -122.4], 8);
    ...
  • f

    future-jewelry-30383

    01/31/2023, 1:05 AM
    Solution to my own question 😅 adding
    hx-include="this"
    isolates the duplicated form to ignore the other identical form state
  • l

    late-king-98305

    01/31/2023, 1:08 AM
    I wouldn't think that htmx would be evaluating that as script - but I'm wading into an area in which I don't have a lot of experience. Your payload is probably useless without the script tags, but you might try taking them out of the return value just to see if that's what's causing the htmx error. (assuming that's something that you could easily do; it wouldn't be a fix, just a debugging step)
  • a

    agreeable-apartment-19546

    01/31/2023, 1:09 AM
    Let me try pulling the second script.
  • a

    agreeable-apartment-19546

    01/31/2023, 1:11 AM
    I think that might be it. Let me look more closely to make sure this response is correctly-formed...
  • a

    agreeable-apartment-19546

    01/31/2023, 1:11 AM
    Looks like my Leaflet pieces that are being built server-side might have syntax issues
  • a

    agreeable-apartment-19546

    01/31/2023, 1:14 AM
    Ah, the response contains
    "
    instead of
    "
  • a

    agreeable-apartment-19546

    01/31/2023, 1:15 AM
    Fun stuff...
  • a

    agreeable-apartment-19546

    01/31/2023, 1:16 AM
    Escaping is not working. Hmmmmm 😄
  • l

    late-king-98305

    01/31/2023, 1:17 AM
    Escaping is always the right decision - except when it isn't... 🙂 The server-side software tries to keep us from shooting ourselves in the foot, but it usually just ends up replacing the real bullets with blanks.
  • a

    agreeable-apartment-19546

    01/31/2023, 1:17 AM
    Cool, I'll see what I can do, maybe there's a "don't escape this stuff" setting in my FastAPI response. Thanks a bunch, super helpful !
  • l

    late-king-98305

    01/31/2023, 1:18 AM
    Glad I could help.
  • a

    agreeable-apartment-19546

    01/31/2023, 1:27 AM
    Quick and dirty solution is to
    autoescape=False
    on Jinja2's
    Environment
    . Will have to scour for collateral damage 😛
  • a

    agreeable-apartment-19546

    01/31/2023, 1:38 AM
    And for damage control, a
    {% autoescape false %}
    block in the template works great. Thanks again Daniel.
  • r

    ripe-action-67367

    01/31/2023, 8:31 AM
    I was unable to reproduce this. I tried it in jsfiddle, and, while I did not have a proper server and used client side templates, the
    unSetBodyClasses()
    method always worked on clicks from
    #unset_update
    , removing the
    .update-On
    class from the body, regardless if
    #unset_update
    element was in the main page or in the response content. Please provide more details about your intended behavior and error messages (if present)
1...100410051006...1146Latest