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

    user

    07/01/2020, 7:12 PM
    Have a div tag with htmx properties that automatically loads data from external API and renders graphs.
  • b

    big-airline-13935

    07/01/2020, 7:36 PM
    Do share...
  • m

    most-jelly-15242

    07/01/2020, 8:47 PM
    @User @User I haven't really dug much into htmx yet, but wouldn't it be possible to trigger a request on load or click, etc. then get the data back and use it to initialize the chart? Something like this:
    Copy code
    js
      document.body.addEventListener('htmx:afterRequest
    ', function(evt) {
        if (evt.target.id == 'graph') {
          const data = JSON.parse(evt.detail.xhr.response);
          // Initialize chart here 
          console.log(data);
        }
      });
    Copy code
    html
    <div id="graph" hx-get="/graph" hx-trigger="load"></div>
  • b

    big-airline-13935

    07/01/2020, 10:03 PM
    The whole reason for using htmx (the way I see it at least) is to fetch html and swap it into the DOM. You're essentially using htmx to fetch JSON and writing JS code to handle it too. I guess it would make sense if you're already using htmx for other things, but it wouldn't be my go-to for this alone.
  • m

    most-jelly-15242

    07/01/2020, 10:06 PM
    Yes, I totally agree. We need server-rendered graphs 🙂
  • b

    big-airline-13935

    07/01/2020, 10:13 PM
    In case anyone is interested in seeing htmx being used in the context of a CMS, I'll be on a livestream demoing and explaining 🌿 Sprig this Friday, all are welcome! https://twitter.com/craftquest_io/status/1278346380537401344
  • b

    big-airline-13935

    07/01/2020, 10:20 PM
    Sprig demos: https://putyourlightson.com/sprig-cookbook
  • m

    most-jelly-15242

    07/01/2020, 10:27 PM
    @User Will you be going into a bit of detail on the internals, how you built it? or is it more about how to use it?
  • b

    big-airline-13935

    07/01/2020, 10:28 PM
    More about how to use it. It's open-source in case you're curious, rather specific to Craft CMS though... https://github.com/putyourlightson/craft-sprig
  • m

    most-jelly-15242

    07/01/2020, 10:30 PM
    Thanks. I am interested in using it on my product for Joomla and WordPress, but haven't gotten to it. It'll probably be a few months, but I already starred your repo to take a look. The demos look very cool!
  • u

    user

    07/02/2020, 1:03 PM
    Examples at htmx.org not showing server requests in bottom debug panel
  • m

    mysterious-toddler-20573

    07/02/2020, 2:02 PM
    ah, I bet that's the event change!
  • m

    mysterious-toddler-20573

    07/02/2020, 2:03 PM
    fix going up now
  • m

    mysterious-toddler-20573

    07/02/2020, 2:04 PM
    I have the www/js marked as "ignore" in my IDE so the htmx.js in there isn't indexed, I'll fix that
  • m

    most-jelly-15242

    07/02/2020, 2:21 PM
    @mysterious-toddler-20573 Would there be any consideration for changing camel cased event names to a hyphenated format, or maybe add support for both? The reason I ask is because that would make it compatible with the Alpine JS event syntax which requires using event names as HTML attributes, and apparently, these are case insensitive. For example,
    htmx:afterRequest
    doesn't work, because it would need to be
    htmx:after-request
    . Here's an example of markup where the two scripts could be use together:
    Copy code
    html
     <div 
        x-data
        hx-get="/load"
        hx-trigger="click"
        @htmx:after-request.window="console.log($event.detail.xhr.response)"
    >
        Load
    </div>
    This could open up some nice possibilities.
  • m

    mysterious-toddler-20573

    07/02/2020, 2:37 PM
    can you explain that a bit more? Why wouldn't @htmx:afterRequest.window work?
  • m

    mysterious-toddler-20573

    07/02/2020, 2:37 PM
    iirc, boostrap uses camel case, I'm surprised that alpine wouldn't work w/ their stuff
  • m

    mysterious-toddler-20573

    07/02/2020, 2:37 PM
    lemme verify
  • m

    mysterious-toddler-20573

    07/02/2020, 2:38 PM
    ah, no, looks like they use dots
  • m

    mysterious-toddler-20573

    07/02/2020, 2:38 PM
    :/
  • m

    mysterious-toddler-20573

    07/02/2020, 2:41 PM
    this is a bit more radical, what if we switched to full colon separators and then recursively triggered events on the entire path:
    Copy code
    htmx:request:after
    
    triggers events
    
    htmx:request:after
    htmx:request
    htmx
  • m

    mysterious-toddler-20573

    07/02/2020, 2:42 PM
    That would make the namespaces actually useful and trivial to use
  • m

    mysterious-toddler-20573

    07/02/2020, 3:42 PM
    @User what do you think? ☝️
  • b

    big-airline-13935

    07/02/2020, 3:45 PM
    Makes sense to switch to hyphens since HTML attributes are case insensitive!
  • b

    big-airline-13935

    07/02/2020, 3:45 PM
    Regarding recursively triggering events, that does sound interesting...
  • b

    big-airline-13935

    07/02/2020, 3:45 PM
    Thinking through the real-world use-cases...
  • m

    mysterious-toddler-20573

    07/02/2020, 3:45 PM
    it makes names spaces actually name spaces...
  • m

    mysterious-toddler-20573

    07/02/2020, 3:46 PM
    wanting to see all "request" related events for an element
  • m

    mysterious-toddler-20573

    07/02/2020, 3:46 PM
    🤷‍♂️
  • b

    big-airline-13935

    07/02/2020, 3:46 PM
    Yeah it certainly adds potential...
1...456...1146Latest