https://htmx.org logo
Join Discord
Powered by
# πŸ”₯-django-htmx
  • s

    shy-zebra-22292

    11/19/2022, 12:59 PM
    if they all update I suspect htmx is not set on the right elements/targets maybe talking with (pseudo)code will help? (btw English is not my primary language but I think City and Town should be Area and Town or State & Town?) I imagine something like this:
  • s

    shy-zebra-22292

    11/19/2022, 1:01 PM
    Both sound cool. No need for code. I can definitely figure it out on my own without much effort πŸ™‚ I was asking more for.. ideas
  • f

    flaky-fish-46395

    11/19/2022, 1:02 PM
    Yea, i kinda messed up 'city' and 'town', should be 'area' or 'country' instead of 'city'. But ty anyway!
  • k

    kind-kite-734

    11/22/2022, 3:43 PM
    Is anyone able to help me with the HX-Location response header? I am probably doing something stupid here. This works:
    return HttpResponse(status=204, headers={"HX-Location": "/portfolio/overview/0182727d-547a-7d85-858e-bdfc7512ca6b"})
    This doesn't:
    return HttpResponse(status=204, headers={"HX-Location": {"path":"/portfolio/overview/0182727d-547a-7d85-858e-bdfc7512ca6b","target":"#details-container"}})
    Even if I exclude the target and just put the path in the second bit of code, it doesn't work. Thanks all
  • k

    kind-kite-734

    11/22/2022, 3:58 PM
    I should also add, the 204 status is used to hide a modal, that also stops working when I use the second bit of code. I can see the 204 response in the chrome inspection window though.
  • t

    tall-dinner-62086

    11/22/2022, 4:02 PM
    Can you also see the value of the header in your dev tools?
  • k

    kind-kite-734

    11/22/2022, 5:11 PM
    Yes, in the response headers I can see this:
  • t

    tall-dinner-62086

    11/22/2022, 5:12 PM
    Why is it single-quoted
  • t

    tall-dinner-62086

    11/22/2022, 5:14 PM
    I don't do django, can you return the entire value as a string? i.e.
    "HX-Location": '{"path":"/.../", "target":"..."}'
  • k

    kind-kite-734

    11/22/2022, 5:32 PM
    Yes, that seems to have fixed the HX-Location issue. The modal closing is still not working in this single case, I will keep playing. Thanks @tall-dinner-62086
  • t

    tall-dinner-62086

    11/22/2022, 5:34 PM
    I don't know why a 204 would close a modal, or how
  • r

    ripe-action-67367

    11/22/2022, 8:01 PM
    https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L3066 FYI, htmx interprets 204 as "do not swap"
  • a

    ancient-shoe-86801

    11/22/2022, 9:10 PM
    @kind-kite-734 I don't know with Django, but when building
    htmx-flask
    , I created a helper to easily generate responses with htmx fields. I want the users to be able to pass a
    dict
    or a string for the location header, and for that to work I had to do this:
    Copy code
    python
    def _stringify(val):
        return val if isinstance(val, str) else json.dumps(val)
    
    ...
    
    resp.headers["HX-Location"] = _stringify(location)
    (where
    location
    can be a string or a dict)
  • a

    ancient-shoe-86801

    11/22/2022, 9:11 PM
    in other words, you might need to `json.dumps`ify your dict, and set the header to that
  • a

    ancient-shoe-86801

    11/22/2022, 9:12 PM
    same applies to other headers, see https://github.com/sponsfreixes/htmx-flask/blob/main/src/htmx_flask/response.py
  • k

    kind-kite-734

    11/23/2022, 4:58 PM
    @ancient-shoe-86801, yes you are correct. I used json.dumps and that is working great. Thanks for the help!
  • a

    ancient-shoe-86801

    11/23/2022, 5:40 PM
    you are welcome! I guess writing a flask extension with tests served me to learn something, lol
  • c

    crooked-winter-42525

    11/28/2022, 3:17 PM
    Anyone know of a straightforward way to delay an OOB swap 1s after the initial response? Maybe not possible out of the box but I know there is a swap delay for regular swaps. Thanks!
  • c

    crooked-winter-42525

    11/28/2022, 3:46 PM
    Quick workaround is to just hide the element I’m swapping out of band and then use a little JavaScript to setTimeout to reveal it. Decent fix to my problem at least.
  • b

    bitter-monkey-50309

    11/28/2022, 4:58 PM
    There's an
    oobBeforeSwap
    event which you could listen for and delay https://htmx.org/events/#htmx:oobBeforeSwap
  • c

    crooked-winter-42525

    11/29/2022, 12:13 AM
    That’s a good idea. Will test that out too.
  • b

    blue-ghost-19146

    11/29/2022, 5:28 PM
    Hi all, I've seen before that file downloads with htmx (or AJAX in general) aren't really possible. I have an endpoint returning a zip file (one-off, not stored in DB) using the
    Content-Disposition
    header. It seems that with htmx, I can swap in whatever content I want but the file download doesn't happen (expected), and without htmx the file download does occur but any other content I want to swap into the page obviously doesn't appear. Has anyone found a way of updating the current page and causing a file download using Django, or through any other relevant approaches?
  • g

    green-activity-6102

    11/29/2022, 5:47 PM
    you could do your swap with some content like "Download will start now" and then hook into the
    afterSwap
    event to set something like
    window.location
    to your download URL to start the download
  • g

    green-activity-6102

    11/29/2022, 5:48 PM
    i suppose it depends on exactly what your want the UI experience to look like
  • q

    quiet-action-5563

    12/01/2022, 12:40 PM
    Hi, I'm getting an error using HTMX in Django with echarts. Follows the HTML that I'm using and the error: <div class="card" hx-get="{% url 'is3_indicador' %}" hx-target="#is3Chart" hx-swap="innerHTML" hx-trigger="load" hx-indicator="#is3Spinner"> IS3: NΓ­vel de escolaridade Loading... {% now "d/m/Y H:i" %} Uncaught DOMException: Node.removeChild: The node to be removed is not a child of this node 2 htmx.js:1730
  • m

    mysterious-toddler-20573

    12/01/2022, 12:48 PM
    is eCharts modifying the dom before the swap?
  • m

    mysterious-toddler-20573

    12/01/2022, 12:53 PM
    one thing to maybe try is removing the spinner for now
  • m

    mysterious-toddler-20573

    12/01/2022, 12:53 PM
    until we get it worked out
  • q

    quiet-action-5563

    12/01/2022, 12:54 PM
    I'll try to remove the spinner and let you know. Thanks!
  • m

    mysterious-toddler-20573

    12/01/2022, 12:54 PM
    also (temporarily) switch to the non-minified verison of htmx so we can see exactly where the exception is happening
1...838485...100Latest