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

    lively-beach-14291

    10/12/2020, 2:09 PM
    Looks like you're doing that with YoYo; although I don't quite grok the structure yet.
  • l

    lively-beach-14291

    10/12/2020, 2:10 PM
    ie, when you update the component server-side, it propagates to client side
  • l

    lively-beach-14291

    10/12/2020, 3:14 PM
    Something like ... https://v3.vuejs.org/guide/component-basics.html but server-side.
  • m

    most-jelly-15242

    10/12/2020, 3:18 PM
    I created an HTMX extension for Yoyo that automatically routes all requests to a specific route. So if I have
    hx-get="increment"
    that triggers a request to
    /yoyo?index.php?component=counter/increment
    . Then on the server side I use the
    component
    parameter to figure out which component needs to be re-rendered.
  • m

    most-jelly-15242

    10/12/2020, 3:19 PM
    So the
    /yoyo
    route is just for updating individual components.
  • m

    most-jelly-15242

    10/12/2020, 3:21 PM
    The extension also gets the component name
    counter
    from the HTML markup
    yoyo:name="counter"
    so it can include it in the request URL.
  • c

    crooked-angle-63874

    10/12/2020, 4:13 PM
    I get a http status 204 (no content) and because I do a full refresh of the page get all blank, how avoid it?
  • m

    mysterious-toddler-20573

    10/12/2020, 4:21 PM
    Do you have to return a 204?
  • c

    crooked-angle-63874

    10/12/2020, 4:28 PM
    I get this from other service that proxy (cloudflare)
  • u

    user

    10/12/2020, 7:14 PM
    is there a way to do something like
    <button hx-get="#template">Click me</button>
    where template is
    <template id="template"><div>hello world</div></template>
    ?
  • u

    user

    10/12/2020, 7:15 PM
    or maybe
    <button hx-select="#template">Click me</button>
  • u

    user

    10/12/2020, 7:16 PM
    i guess, this might be out of scope, could be hyperscript related
  • m

    mysterious-toddler-20573

    10/12/2020, 8:03 PM
    Yeah, a little out of scope, but we have talked about making hx-get support
    javascript:
  • m

    mysterious-toddler-20573

    10/12/2020, 8:05 PM
    @User we should be ignoring a 204
  • m

    mysterious-toddler-20573

    10/12/2020, 8:05 PM
    Copy code
    js
                            // don't process 'No Content'
                            if (this.status !== 204) {
  • u

    user

    10/12/2020, 8:16 PM
    now that i think about this, it could just be an extension
  • u

    user

    10/12/2020, 8:16 PM
    doesn't need to be in core
  • c

    crooked-angle-63874

    10/12/2020, 9:16 PM
    @User look like is correct. I was looking at the old htmx
  • c

    crooked-angle-63874

    10/12/2020, 9:17 PM
    the master version look like have some fixes I was not aware!
  • c

    crooked-angle-63874

    10/12/2020, 9:17 PM
    I will check if this work now
  • m

    most-jelly-15242

    10/16/2020, 8:24 PM
    @User Is there a way to make the
    beforeend
    swap only append when the ID isn't already there? If it's there then it swaps the existing element? A use-case for this would be for modals where you have a list of items with edit buttons. You click one button, it appends the modal HTML to the body using htmx. Then you close the modal, click another button and instead of appending a new modal, it re-uses the existing one based on the existing ID attribute. Or maybe there's a more practical way to do this? The reason why I want to append the modal to begin with, instead of just having a div there on page load, is because I may not have control over the entire page.
  • m

    mysterious-toddler-20573

    10/16/2020, 8:29 PM
    hmmm
  • m

    most-jelly-15242

    10/16/2020, 8:34 PM
    I could always use Javascript 🤯 to append an element with a known ID to the body on load and use that one.
  • m

    most-jelly-15242

    10/16/2020, 8:35 PM
    I was just wondering what others do in this case.
  • m

    most-jelly-15242

    10/16/2020, 8:42 PM
    I also looked at the extension system for this, but couldn't find a simple way to do it.
  • m

    most-jelly-15242

    10/16/2020, 10:34 PM
    Ok, so I solved it using the
    htmx:processedNode
    event. Read
    hx-target
    value there. If it's an ID (e.g.
    #some-id
    ), then find the element and create if it's not already there.
  • m

    mysterious-toddler-20573

    10/16/2020, 11:13 PM
    excellent!
  • m

    most-jelly-15242

    10/16/2020, 11:24 PM
    You can pretty much do anything with the events system 🙂
  • m

    mysterious-toddler-20573

    10/16/2020, 11:35 PM
    that's the idea!
  • m

    mysterious-toddler-20573

    10/17/2020, 7:32 PM
    https://twitter.com/htmx_org/status/1317549028398133249
1...555657...1146Latest