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

    bland-coat-6833

    09/01/2022, 1:34 PM
    yeah... interesting. I suppose we can target a
    .class
    with htmx, so it's not quite the same as OOB
  • m

    mysterious-toddler-20573

    09/01/2022, 1:35 PM
    (fwiw, in rails I toggle layouts with a request wrapper, rather than directly in the templates, when handling boosted links)
  • b

    bland-coat-6833

    09/01/2022, 1:35 PM
    Almost a React style "these are the bits that need swapping out"
  • b

    bland-coat-6833

    09/01/2022, 1:37 PM
    I suppose it's a bit of a mix as well - if you have a "standard" layout with header, side bar etc, and then the main container content, you'd probably have multiple templates for the different pages that fill up the content container, and then each of them would have fragments as needed.
  • b

    bland-coat-6833

    09/01/2022, 1:37 PM
    i.e. Not every template needs all of the HTML.
  • b

    bland-coat-6833

    09/01/2022, 1:39 PM
    That https://enhance.dev/ is interesting though - you just create pieces of html in a file and they appear as routes.
  • r

    rapid-optician-10719

    09/01/2022, 1:41 PM
    and I feel like they're interested in some first-class htmx support (@mysterious-toddler-20573 👀 ) https://twitter.com/brianleroux/status/1565103292702916609
  • b

    bland-coat-6833

    09/01/2022, 1:41 PM
    Not sure if that counts as a different approach to doing something similar. Could you have all of the fragments under the same folder and then is your "template" just the folder contents. e.g. it's a IDE presentational issue - if you have them all in split windows then do you have "Visual Locality of Behaviour"? 😄
  • b

    bland-coat-6833

    09/01/2022, 1:42 PM
    https://tenor.com/view/oh-well-thats-wonderful-johnny-rose-johnny-eugene-levy-schitts-creek-gif-20290435
  • r

    rapid-optician-10719

    09/01/2022, 1:43 PM
    I would pay to eavesdrop on that zoom call 😅
  • t

    tall-river-23601

    09/01/2022, 1:43 PM
    Good point. Will give this some more thought.
  • m

    mysterious-toddler-20573

    09/01/2022, 1:45 PM
    yep, I DM'd him, always happy to chat w/ folks
  • w

    worried-hair-75253

    09/01/2022, 2:22 PM
    Hey sy, I use gridstack and HTMX together successfully... Are you essentially saying that gridstack events are not wired up to that widget created in the
    .addWidget()
    call? Here is what I do. I have a hidden DIV as the HTMX Target, then I do this:
    Copy code
    let container = htmx.find('#newWidgetTargetContainer');
                let widgetelement = container.firstElementChild.cloneNode(true);
                container.firstElementChild.remove();
                let grid = document.querySelector('.grid-stack').gridstack;
                grid.addWidget(widgetelement);
                htmx.process(widgetelement);
  • f

    fierce-application-41107

    09/01/2022, 2:23 PM
    Ah!!! htmx.process is what I wanted
  • f

    fierce-application-41107

    09/01/2022, 2:23 PM
    thank you!!
  • f

    fierce-application-41107

    09/01/2022, 2:26 PM
    is there any advantage to htmx.find over document. stuff?
  • f

    fierce-application-41107

    09/01/2022, 2:27 PM
    I personally htmx swap it to an invisible div then add the innerHTML to the widget, then remove the invisible element
  • w

    worried-hair-75253

    09/01/2022, 2:29 PM
    seems like essentially the same thing. in your case perhaps you may have some thin wrapper around your actual gridstackItem content. in my case, that
    widgetelement
    is the entire gridstackItem, not just the innerHTML ... again, basically same thing
  • f

    fierce-application-41107

    09/01/2022, 2:30 PM
    awesome
  • f

    fierce-application-41107

    09/01/2022, 2:31 PM
    I do need to clone it if I want an element to run process on though
  • f

    fierce-application-41107

    09/01/2022, 2:31 PM
    though I could find the new element in the grid then do it
  • w

    worried-hair-75253

    09/01/2022, 2:32 PM
    I use clone to make sure it is a true DOM element being added, not just a segment of HTML
  • f

    fierce-application-41107

    09/01/2022, 2:34 PM
    hm your way sounds better
  • f

    fierce-application-41107

    09/01/2022, 2:37 PM
    Do you do something to eval scripts in the included widget properly?
  • w

    worried-hair-75253

    09/01/2022, 2:39 PM
    I do not... I have a little sprinkle of Alpine in each widget, but when added and processed, that all "just works" (tm)
  • f

    fierce-application-41107

    09/01/2022, 2:55 PM
    Hmm, didn't work for me, so I had to do this:
    Copy code
    document.addEventListener('load-widget', function(event) {
          grid.removeWidget("drilldown-widget-results");
    
          let container = htmx.find('#drilldown-widget');
          var scripts = htmx.findAll(container, "script");
          let widgetelement = container.firstElementChild.cloneNode(true);
          container.firstElementChild.remove();
          //let grid = document.querySelector('.grid-stack').gridstack;
          grid.addWidget(widgetelement);
    
          htmx.process(widgetelement);
          for (var i = 0; i < scripts.length; i++) {
            eval(scripts[i].innerHTML);
          }
        });
    and in the widget:
    Copy code
    var widget_event = new Event('load-widget');
      document.dispatchEvent(widget_event);
  • f

    fierce-application-41107

    09/01/2022, 2:55 PM
    events avoid a race condition between the widget being loaded on initial load before the grid is loaded
  • f

    fierce-application-41107

    09/01/2022, 2:55 PM
    since the same widget is included for both
  • f

    fierce-application-41107

    09/01/2022, 2:55 PM
    (first page load and when the user clicks the search button)
  • f

    fierce-application-41107

    09/01/2022, 2:56 PM
    do you happen to have a handy snippet for replacing a widget while keeping the size?
1...806807808...1146Latest