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

    stocky-dentist-80693

    05/18/2023, 8:33 AM
    Every input wrapped inside the will be included in the request - as long as the inputs each have a
    name
    attribute. If the filter inputs can't be inside the form for whatever reason, you can also add a
    form
    attribute to each filter input to link it to the tag by ID, which should still work. Alternatively, if you want more control over other htmx directives like target/swaps/etc, you can skip hx-boost, and use
    hx-get
    on the form along with
    hx-push-url="true"
    .
  • a

    astonishing-cpu-59399

    05/18/2023, 9:46 AM
    hx-trigger="load"
    is not working on boosted links. Anyone have idea?
    Copy code
    <!-- this is working, triggering GET /subpage after load-->
    <div>
      <a hx-get="/subpage" hx-trigger="load">Sub Page</a>
    </div>
    
    <!-- this is not working, not triggering GET /subpage after load -->
    <div hx-boost="true">
      <a href="/subpage" hx-trigger="load">Sub Page</a>
    </div>
  • m

    mammoth-family-48524

    05/18/2023, 10:54 AM
    You could return a blank form on success. Another way is to use HX-Trigger response header to call a JavaScript function which has a form.reset() call.
  • s

    shy-knife-59740

    05/18/2023, 1:06 PM
    hey, idk where to post this but
  • s

    shy-knife-59740

    05/18/2023, 1:06 PM
    https://simpleicons.org/
  • s

    shy-knife-59740

    05/18/2023, 1:07 PM
    can someone add the htmx logo to simpleicons?
  • s

    shy-knife-59740

    05/18/2023, 1:07 PM
    would be usefull to use on badges around projects and stuff
  • s

    shy-knife-59740

    05/18/2023, 1:07 PM
    (imgshields uses simpleicons)
  • i

    icy-vase-29164

    05/18/2023, 1:15 PM
    Hey all, In firefox when the browser sleeps a tab and I click it, it comes back as just the HTML fragment that loaded, not the entire page. A refresh fixes this, but is there any way to address this behavior? I thought perhaps it was the caching mechanism but after setting the vary header the behavior persists.
  • g

    gifted-airline-5816

    05/18/2023, 3:38 PM
    I was able to replicate this, not sure how we might work around it with htmx. Unrelated but I'm also seeing JS errors popping up on older sites where JS is reloading while using the JS so should already be loaded and best current guess is that it's related to tab unloading across chrome/firefox/safari also.
  • g

    great-cartoon-12331

    05/18/2023, 4:24 PM
    yes, see https://discord.com/channels/725789699527933952/725789747212976259/1104985302625419344
  • g

    great-cartoon-12331

    05/18/2023, 4:32 PM
    actually it's slightly more complex than i said there, to correctly distinguish htmx requests and handle caching correctly, i am checking both the
    HX-Request
    header and the
    ?hx=1
    query param. otherwise a user might manually enter a URL with
    ?hx=1
    param and hit Enter, but we don't want to render a partial for that because it's not an htmx request.
  • g

    gifted-airline-5816

    05/18/2023, 4:37 PM
    So when a tab comes back from unload/sleep does browser issue a new GET request to url without the ?hx=1 url is made to server? Or is it loading from cache the last version of page without param? I will try to test this afternoon.
  • g

    great-cartoon-12331

    05/18/2023, 4:38 PM
    it's requesting exactly what's in the URL bar
  • f

    freezing-waitress-26396

    05/18/2023, 6:55 PM
    Godspeed
  • s

    shy-zebra-22292

    05/18/2023, 7:25 PM
    why not only check the header if (hasHeader('HX-Request) && haders['HX-Request'] === true) { // render partial } else { // render whole page }}
  • s

    shy-zebra-22292

    05/18/2023, 7:25 PM
    ?
  • g

    great-cartoon-12331

    05/18/2023, 7:46 PM
    explained in the message i linked to
  • g

    great-cartoon-12331

    05/18/2023, 7:56 PM
    actually i think i just found a better way: https://github.com/bigskysoftware/htmx/issues/1229#issuecomment-1553572220
  • g

    great-cartoon-12331

    05/18/2023, 7:57 PM
    i'll try this later today [EDIT: just tried right now–couple lines changed. works perfectly]
  • s

    square-analyst-94375

    05/18/2023, 7:57 PM
    How do you 'uninherit' or disable hx-include ? For example my parent element has an hx-include that I don't want to include on a child (
    hx-include="false"
    didn't work)
  • m

    mammoth-family-48524

    05/18/2023, 9:38 PM
    https://htmx.org/attributes/hx-disinherit/
  • m

    mammoth-family-48524

    05/18/2023, 9:39 PM
    You were so close with “uninherit” 😄
  • s

    square-analyst-94375

    05/18/2023, 9:39 PM
    Thanks! hx-dead-to-me, it is so obvious 😉
  • g

    great-cartoon-12331

    05/18/2023, 9:53 PM
    i ended up with something similar after all
    Copy code
    ocaml
    let htmx req =
      match Dream.header req "Accept" with
      | Some "text/html;hx=1" -> true
      | _ -> false
  • g

    great-cartoon-12331

    05/18/2023, 11:45 PM
    you will need a tiny bit of custom-written JavaScript:
    Copy code
    javascript
      // On form submit, clear the form.
      document.addEventListener('htmx:afterOnLoad', evt => {
        const frm = evt.detail.elt;
        if (frm instanceof HTMLFormElement) {
          frm.reset();
        }
      });
    
      // If there's an error response, show it in the toast
      document.addEventListener('htmx:responseError', evt => {
        document.getElementById('toast').outerHTML =
          `<p id="toast" class="error">${evt.detail.xhr.responseText}</p>`;
      });
  • a

    aloof-crayon-56651

    05/19/2023, 4:49 AM
    RE: Stack Overflow survey

    https://cdn.discordapp.com/attachments/725789747212976259/1108979717496897556/2023-05-19_13.47.53.png▾

    https://cdn.discordapp.com/attachments/725789747212976259/1108979717786320916/2023-05-19_13.48.07.png▾

  • b

    bland-rainbow-1285

    05/19/2023, 7:31 AM
    If there is error only the Error message (Error Message get updated and Form Data remain same if there is success the I can return Blank Form
  • b

    busy-ocean-3407

    05/19/2023, 7:55 AM
    I know that you can Use HTMX to retrieve client data a in Flask server like this : index.html : Submit app.py : @app.route('/') def home(): return render_template('index.html') @app.route('/submit_form', methods=['POST']) def submit_form(): # Use the
    request.form
    object to get the form data. username = request.form.get('username') password = request.form.get('password') print(username,password) # Now you can use
    username
    and
    password
    in your logic... # Always return a response return "Form data received!" However There seems to be no possibility to retrieve username/password if I need the submit button to be outside the form. I can be done easily with vanilla javascript. NB: hx-vals="{json: getFormValues()}" did not solve the issue .* I am looking for a confirmation that it is not possible without javascript.*
  • b

    bland-rainbow-1285

    05/19/2023, 8:44 AM
    I am returning 417 status but event is not firing I have added script tag when returning New Blank Form
1...113311341135...1146Latest