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

    astonishing-barista-36240

    02/16/2023, 1:04 PM
    gotcha, thanks for the update.. I'll have to keep looking and evaluating. leaning towards https://github.com/jefago/tiny-markdown-editor at the moment
  • r

    refined-waiter-90422

    02/16/2023, 2:06 PM
    Looks slick
  • r

    refined-manchester-67193

    02/16/2023, 9:40 PM
    Can I pass a Javascript function to
    hx-get
    ? I have somewhat of a convoluted use-case :/
  • g

    gorgeous-ghost-95789

    02/16/2023, 9:41 PM
    No, hx-get will only take a URL. But there should be other ways around. What's your use case?
  • g

    gorgeous-ghost-95789

    02/16/2023, 9:42 PM
    For more complicated logic, you will probably have to lean on events in Javascript/Hyperscript.
  • r

    refined-manchester-67193

    02/16/2023, 9:49 PM
    So I have an infinite scrolling list of items. I built a generic modal that can hold different contents, so kind of like a modal-wrapper. In this case though, this generic modal is holding an inner modal that is supposed to filter the items in the current view by sending a request to the current view, with altered query-params. Basically sending an
    hx-get
    that looks something like:
    items?type=Remix&type=Album&period=future
    . So here's one issue with HTMX that I still haven't found an elegant issue to solve: how do I "unpack" a dictionary or list into query params. Say the user selected two buttons (toggles) with
    Album
    and
    Remix
    , I want to translate that to query params such as the
    hx-get
    URL is now
    type=Remix&type=Album
    .
  • g

    gorgeous-ghost-95789

    02/16/2023, 9:59 PM
    @refined-manchester-67193 That would probably be done on your server side. What language are you using to generate your HTML(x)?
  • r

    ripe-action-67367

    02/16/2023, 10:00 PM
    Request fails, because CORS, but as you can see, the values are included in the URL from the form
  • r

    ripe-action-67367

    02/16/2023, 10:02 PM
    I used hx-include, because you have infinite scroll, so I assume that the element with hx-get is not the filter form
  • r

    ripe-action-67367

    02/16/2023, 10:06 PM
    Alternatively, you can use hx-vals
    js:{}
    syntax to dynamically load values (I used constant array, but you can use any JS expression, including function calls). This is useful, if your filters are not accessible by hx-include and you are forced to get the values via JS from some storage.
  • r

    ripe-action-67367

    02/16/2023, 10:06 PM
    References: https://htmx.org/attributes/hx-vals/ https://htmx.org/attributes/hx-include/
  • r

    refined-manchester-67193

    02/16/2023, 10:08 PM
    Thanks @gorgeous-ghost-95789 and @ripe-action-67367 - both make sense. @gorgeous-ghost-95789 - the filter modal is independent from the infinite scrolling area and does not refresh alongside it. I think I have a design flow with how I built both the infinite scroll and the modal rendering. I'll let you know what I end up with.
  • r

    refined-manchester-67193

    02/16/2023, 11:20 PM
    Hmmm, #796428329531605032 or #725789747212976259 question? How can I modify the
    hx-get
    attr of an HTML element, and let
    htmx
    know about the change, before
    htmx
    gets to make the request? (the
    hyperscript
    trigger and the
    htmx
    are on the same element, and they it's the same triggger)
  • r

    refined-manchester-67193

    02/16/2023, 11:44 PM
    Hmmm, I'm getting an
    htmx:historyCacheError
    almost on every
    push-url
    , but it seems like history is working fine..?
  • g

    gorgeous-ghost-95789

    02/16/2023, 11:53 PM
    Yeah, a lot depends on the specific UX. You may have a scenario where you need to update two regions of the page at once. If that's true, there are three generally accepted options: 1) OOB swaps https://htmx.org/attributes/hx-swap-oob/ 2) Use events to trigger a second load on the page (my fave) 3) Just reload the whole area, which usually works fine because it's not as expensive as you'd think. Although in your case, you might consider #3, because I'd guess that resetting the filters/sorting on an infinite scroll should bring you back to the top of a new set of results. yes?
  • r

    refined-manchester-67193

    02/16/2023, 11:57 PM
    I got this one to work with a lot of
    hyperscript
    hackery. Now having htmx:historyCacheError which seem hard to debug..
  • g

    gorgeous-ghost-95789

    02/16/2023, 11:57 PM
    😦
  • r

    refined-manchester-67193

    02/17/2023, 12:02 AM
    It's like htmx is magically able to restore a server-side rendered modal (even after it was closed) when I hit the back button which is both weird and disruptive.
  • r

    refined-manchester-67193

    02/17/2023, 12:04 AM
    How can I tell HTMX to put a URL in the history, but not to mess with the way the back button works? just let the page render regularly.
  • m

    mysterious-toddler-20573

    02/17/2023, 12:23 AM
    set
    htmx.config.historyCacheSize
    to 0, which will disable it and then htmx will issue a full page refresh on back button navigation
  • r

    refined-manchester-67193

    02/17/2023, 12:39 AM
    @mysterious-toddler-20573 you the man!
  • r

    refined-manchester-67193

    02/17/2023, 12:43 AM
    @mysterious-toddler-20573 is htmx still any kind of caching or magic in this case? with that setting, the issue of having previous DOM state is gone, but: I'm seeing the URL instantly switch back to the previous once, but it seems like the "whole page" isn't getting refreshed, only the items that should have (which is kinda weird). Notably, the browser tab doesn't show a spinner, and there is no feedback whatsoever that we are indeed loading back information in the previous URL. Am I missing something?
  • r

    refined-manchester-67193

    02/17/2023, 12:47 AM
    Recorded a little demonstration
  • m

    mysterious-toddler-20573

    02/17/2023, 3:40 AM
    there is a bug and PR that. might be causing what you are seeing: https://github.com/bigskysoftware/htmx/pull/1222
  • m

    mysterious-toddler-20573

    02/17/2023, 3:40 AM
    https://github.com/bigskysoftware/htmx/issues/1221
  • m

    mysterious-toddler-20573

    02/17/2023, 3:41 AM
    intend to merge it soon, sorry, been very busy
  • r

    ripe-piano-71543

    02/17/2023, 8:37 AM
    Hi guys, I am a quite new to front end developing and recently discoverd htmx and I wonder if it is possible to host htmx websites on static site providers like Netlify, Render or even github? (Of course, the backend is running somewhere else.)
  • b

    brash-microphone-56568

    02/17/2023, 9:19 AM
    Hi there ! Is there a standalone (not cdn) version of HTMX ? I have download last min.js file on a CDN but I have an error with it... Do I miss something ?
  • b

    brash-microphone-56568

    02/17/2023, 9:28 AM
    Redownloading from CDN seems to fix the problem...
  • a

    adventurous-ocean-93733

    02/17/2023, 10:00 AM
    I don’t have experience of this myself and using htmx cross-domain (eg static site at frontend.netlify.com with ajax calls to backend.yoursite.com) is definitely not the happy path but I don’t see why it wouldn’t work. Be prepared for CORS issues though. https://htmx.org/docs/#cors
1...102210231024...1146Latest