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

    melodic-father-55349

    09/23/2022, 1:09 PM
    https://htmx.org/examples/tabs-hateoas/ (for returning html) https://htmx.org/examples/tabs-hyperscript/ (using hyperscript)
  • g

    gifted-appointment-5037

    09/23/2022, 1:27 PM
    🤩
  • g

    gifted-appointment-5037

    09/23/2022, 1:35 PM
    I'd missed what hyperscript was ... unbelievable ... so good.
  • g

    gentle-finland-44476

    09/23/2022, 1:43 PM
    Hey all you smart people. I am working on a chat messaging project that uses HTMX over a websocket.
  • g

    gentle-finland-44476

    09/23/2022, 1:44 PM
    I'm having trouble with adding a typing indication. Basically, I need to use hx-swap-oob to add an element for each user when they start typing.
  • g

    gentle-finland-44476

    09/23/2022, 1:46 PM
    I'm sending this over the websocket on every keypress: `` {{typing_user.username}} `` I'm using hyperscript to remove the indicator after 10 seconds. The problem is, multiple typing indicators will come up for the same user.
  • g

    gentle-finland-44476

    09/23/2022, 1:48 PM
    I need to somehow add the element #typing-indicator-{{typing_user.id}} within the #msg-area-currently-typing only if it doesn't already exist. If it does already exist, I need to replace it so the hyperscript counter resets.
  • t

    tall-dinner-62086

    09/23/2022, 1:49 PM
    That
    swap-oop="beforeend"
    just sounds wrong to me
  • t

    tall-dinner-62086

    09/23/2022, 1:49 PM
    Put the oob swap on the actual indicator maybe?
  • g

    gentle-finland-44476

    09/23/2022, 1:53 PM
    I could do that if it was a 1-1 conversation, but it's a group chat with multiple people. There might be 1,2,3+ users typing at one time. There isn't an existing #id for each user that could possibly be typing
  • t

    tall-dinner-62086

    09/23/2022, 1:55 PM
    What's
    typing_user.id
    then?
  • t

    tall-dinner-62086

    09/23/2022, 1:55 PM
    oh
  • t

    tall-dinner-62086

    09/23/2022, 1:55 PM
    I think I get ya
  • t

    tall-dinner-62086

    09/23/2022, 1:56 PM
    Try adding it there as well as the one on the parent
  • t

    tall-dinner-62086

    09/23/2022, 1:56 PM
    Not super sure if that works, but it's one of those things that sounds like it might
  • s

    silly-soccer-20915

    09/23/2022, 6:19 PM
    hi everyone! I am trying to stop an out of band swap in the presence of a specific header in the response, but I am not being able to find the xhr property in the events detail property:
    Copy code
    <script>
    htmx.defineExtension('exclude-from-oob-swap', {
         onEvent: function (name, evt) {
               if(name === "htmx:oobBeforeSwap"){
                   console.log(name);
                   console.log(evt.detail);
                   console.log(evt.detail.xhr);
                   console.log(evt.xhr);
               }
         }
    });
    </script>
    Am I approaching something the wrong way?? Thanks for further answers!
  • m

    mysterious-toddler-20573

    09/23/2022, 6:27 PM
    detail.xhr should be in that event
  • s

    silly-soccer-20915

    09/23/2022, 6:29 PM
    as an argument of the anonymous function??
  • s

    silly-soccer-20915

    09/23/2022, 6:31 PM
    or under evt.detail.xhr? (my initial thought!)
  • m

    mysterious-toddler-20573

    09/23/2022, 6:33 PM
    yes, under evt.detail.xhr
  • m

    mysterious-toddler-20573

    09/23/2022, 6:33 PM
    what is it printing out?
  • s

    silly-soccer-20915

    09/23/2022, 6:38 PM
    added a console log arguments() right after name
  • s

    silly-soccer-20915

    09/23/2022, 6:40 PM
    not sure if worth mentioning, the extension is placed on the element with the hx-swap-oob
  • s

    silly-soccer-20915

    09/23/2022, 6:41 PM
    https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L724 <-- maybe it's missing here??
  • s

    silly-soccer-20915

    09/23/2022, 8:52 PM
    I think this should fix it? https://github.com/bigskysoftware/htmx/pull/1057
  • s

    silly-soccer-20915

    09/23/2022, 8:52 PM
    but not sure tbh ._.
  • s

    silly-soccer-20915

    09/23/2022, 9:45 PM
    managed to come up with this:
    Copy code
    htmx.defineExtension('exclude-from-oob-swap', {
                onEvent: function (name, evt) {
                    if (name === "htmx:oobBeforeSwap") {
                        var xhr = evt.detail.xhr;
                        var stop = xhr.getResponseHeader('hx-stop-oob') === "true";
                        if(stop){
                            evt.detail.shouldSwap = false;
                        }
                    }
                }
    });
    but it stops the actual swap that should append the content, altogether with the oob swap ._.
  • s

    silly-soccer-20915

    09/23/2022, 10:06 PM
    Copy code
    <div hx-swap-oob="true"
         hx-ext="exclude-from-oob-swap"
         class="list-parent"
         class="uk-container uk-margin-large-bottom"
            <ul class="list">
                    <li class="list-item">
                       <!-- if (this is not the last page of items) -->
                            <span class="uk-width-1-1 trigger"
                                  hx-get="/page2"
                                  hx-trigger="revealed"
                                  hx-indicator="#spinner"
                                  hx-target=".list-parent .list-item:last-child"
                                  hx-select=".list-parent .list-item"
                                  hx-vals='{"infinite-loader": "true"}'
                                  hx-swap="afterend">
                            </span>
                      <!-- end if -->
                    </li>
            </ul>
        
          <div id="spinner" class="htmx-indicator uk-text-center"></div>
    </div>
  • s

    silly-soccer-20915

    09/23/2022, 10:13 PM
    Here's a sample of the markup where the trick lies in the nested hx-get within the hx-swap-oob marked element. Normally, without the extension the issue is that the oob-swap overwrites the initial hx-swap from the nested span. If I remove the hx-oob-swap it just works as expected and keeps adding the list items to the list, but of course the oob-swap doesn't work. This breaks a search form within the same page that assumes that the results will get oob-swapped. Maybe I should rethink how that works ? I like using oob-swap for form results since I can have multiple form controls (for example, desktop and mobile versions of filters, as completely separate markup), and it just magically works, until now lol
  • s

    silly-soccer-20915

    09/23/2022, 10:15 PM
    I thought of hx-sync too but i think it doesn't work with hx-swap-oob??
1...835836837...1146Latest