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

    shy-knife-59740

    04/18/2023, 12:50 PM
    im mentally ill
  • s

    shy-knife-59740

    04/18/2023, 12:50 PM
    XD
  • s

    shy-knife-59740

    04/18/2023, 12:50 PM
    sorry
  • r

    ripe-action-67367

    04/18/2023, 12:50 PM
    Copy code
    html
    
    <script src="https://unpkg.com/htmx.org@1.9.0"></script>
    
    <button class="cookie-btn cookie-confirm"
            hx-get="/createsession"
            hx-on="click: alert('Done making a request!')
                   htmx:afterRequest: alert('Done making a request!')">
        Okay
    </button>
    this works
  • s

    shy-knife-59740

    04/18/2023, 12:51 PM
    i was literally staring at https://htmx.org/attributes/hx-on/ for half an hour
  • s

    shy-knife-59740

    04/18/2023, 12:56 PM
    hmm, i dont seem to get any alerts
  • r

    ripe-action-67367

    04/18/2023, 12:57 PM
    I just copied this into codepen, it worked. Check your htmx version and error logs
  • s

    shy-knife-59740

    04/18/2023, 12:57 PM
    "1.8.6"
    and no error logs
  • r

    ripe-action-67367

    04/18/2023, 12:58 PM
    1.8.6 does not have hx-on attribute, it was introduced in 1.9.0 https://github.com/bigskysoftware/htmx/blob/master/CHANGELOG.md
  • s

    shy-knife-59740

    04/18/2023, 12:58 PM
    aaaaaaaaaah
  • s

    shy-knife-59740

    04/18/2023, 12:58 PM
    understandable
  • s

    shy-knife-59740

    04/18/2023, 12:59 PM
    also one more question since i see that there is a gzip version of htmx, how would someone load that into html?
  • r

    ripe-action-67367

    04/18/2023, 1:01 PM
    if you load it via CDN, it's already compressed (unpkg uses brotli), so don't worry about it
  • r

    ripe-action-67367

    04/18/2023, 1:02 PM
    if you host htmx on your own server, you would have to configure compression yourself, which depends on your setup
  • s

    shy-knife-59740

    04/18/2023, 1:02 PM
    okay thanks!
  • s

    shy-knife-59740

    04/18/2023, 1:03 PM
    is
    click
    nescessary here if i dont display any event?
  • r

    ripe-action-67367

    04/18/2023, 1:04 PM
    I just used events you provided in your example. You can listen for any event, of course
  • s

    shy-knife-59740

    04/18/2023, 1:05 PM
    yea but wont it automatically chose the click event for a button when there is
    htmx:afterRequest
    in
    hx-on
    ?
  • s

    shy-knife-59740

    04/18/2023, 1:05 PM
    question out of curiosity
  • r

    ripe-action-67367

    04/18/2023, 1:05 PM
    not sure what you mean by "chose"
  • r

    ripe-action-67367

    04/18/2023, 1:06 PM
    htmx parses this attribute value and sets up all necessary event listeners
  • s

    shy-knife-59740

    04/18/2023, 1:06 PM
    yea but without the hx-on, it still will make the request on button click
  • r

    ripe-action-67367

    04/18/2023, 1:06 PM
    ah, you mean htmx's internal event handlers
  • r

    ripe-action-67367

    04/18/2023, 1:08 PM
    event handlers are independent from each other, so when the button is clicked, all handlers should be called
  • r

    ripe-action-67367

    04/18/2023, 1:08 PM
    that means that alert will be shown and htmx will send the request
  • r

    ripe-action-67367

    04/18/2023, 1:12 PM
    I also have a suspicion, that you are missing https://htmx.org/attributes/hx-trigger/ from your picture. hx-on is purely for client-side scripting purposes, so that developers don't need to install hyperscript or fiddle with vanilla JS when handling simple cases. It does not really affect internal htmx logic
  • s

    shy-knife-59740

    04/18/2023, 1:15 PM
    hm
  • s

    shy-knife-59740

    04/18/2023, 1:16 PM
    Copy code
    html
    <button class="cookie-btn cookie-confirm"
            hx-get="/createsession"
            hx-on="click; htmx:afterRequest: window.location.reload()">
        Okay
    </button>
    thats basically what im trying to do but it wont work..
  • r

    ripe-action-67367

    04/18/2023, 1:16 PM
    remove
    click;
  • s

    shy-knife-59740

    04/18/2023, 1:17 PM
    ah
1...109610971098...1146Latest