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

    cuddly-keyboard-70746

    10/25/2022, 5:44 AM
    you can actually use htmx and having the site work without js. Forms, links etc. You can use the presence of a header to determine if this is a regular request or an htmx request, I can't remember the exact header though.
  • b

    boundless-leather-51644

    10/25/2022, 6:17 AM
    Yep but the HTML page still needs to use
    <script src="/webjars/htmx.org/dist/htmx.min.js"></script>
    if we want to use htmx and this is a .... JS 😉
  • t

    tall-dinner-62086

    10/25/2022, 8:39 AM
    One of the neat things about htmx is that you can take a boring old multi page app (read: a normal fucking website) and add arbitrary dynamic loading to it as progressive enhancement. For example, your server can look at a request made to
    /users
    and either respond with a full page, or with just the partial html fragment of the actual list of users if it detects the request was made by htmx. That is what's meant by "your site can work without js".
  • f

    freezing-waitress-26396

    10/25/2022, 8:51 AM
    Yes, the graceful non-JS fallback
  • v

    victorious-match-64854

    10/25/2022, 1:19 PM
    wow these projects look cool
  • m

    miniature-lizard-24702

    10/25/2022, 4:43 PM
    in other words, you'd load a webpage that does not use javascript and append hx attributes to load a fragment/page that supports js. if js is enabled it will replace the basic component
  • m

    miniature-lizard-24702

    10/25/2022, 4:44 PM
    is that correct? Or that an extra step?
  • s

    silly-megabyte-79345

    10/26/2022, 12:05 AM
    hey. quick question
  • s

    silly-megabyte-79345

    10/26/2022, 12:05 AM
    how would you go about setting a display to none an an element in the dom after issuing an htmx request from a form
  • s

    silly-megabyte-79345

    10/26/2022, 12:06 AM
    basically it's a container that's blocking the view of my indicator
  • g

    great-cartoon-12331

    10/26/2022, 12:49 AM
    normally the response of the form submission would be some html fragment that would set the display to none and make any other changes
  • g

    green-activity-6102

    10/26/2022, 1:04 AM
    i think you're asking how to cover up a dom element (to effectively disable it and show that something is loading)?
  • g

    green-activity-6102

    10/26/2022, 1:05 AM
    just while the request is in flight?
  • g

    green-activity-6102

    10/26/2022, 1:05 AM
    you can use the
    .htmx-request
    class for that, and override the CSS with display properties https://htmx.org/attributes/hx-indicator/
  • s

    silly-megabyte-79345

    10/26/2022, 1:46 AM
    @green-activity-6102 thats awesome , i think that's what i was looking for !
  • s

    silly-megabyte-79345

    10/26/2022, 1:47 AM
    @great-cartoon-12331 i was looking to change things upon request , not after which i know is a little unusual for htmx stuff
  • g

    great-cartoon-12331

    10/26/2022, 3:16 AM
    got it, the css should work if the requesting element is the one you want to hide
  • b

    boundless-leather-51644

    10/26/2022, 7:04 AM
    Hi
  • b

    boundless-leather-51644

    10/26/2022, 7:05 AM
    Is there an example available about https://htmx.org/docs/#boosting as this is not clear for me what boost do or not ?
  • c

    chilly-refrigerator-94141

    10/26/2022, 12:45 PM
    Hello, I can't find the right JS event in order to know when
    hx-boost
    is "done". Any clue, someone?
  • c

    cuddly-keyboard-70746

    10/26/2022, 1:50 PM
    boost was a little vague for me too. What it does is ignore the head tag, and replace your html body with the response body (all with ajax). the idea is that using ajax and ignoring will boost the speedyness or perceived speed or the page. I haven't tried it myself but, if a speedier load is not what you are after it doesn't really do much. boost is meant to enrich simple forms and links, if you already have hx-request and thise headers hx-boost shouldn't be used as it is redundant
  • b

    boundless-vase-80440

    10/26/2022, 2:12 PM
    boost swaps the body innerHTML by default but that can overridden
  • b

    boundless-leather-51644

    10/26/2022, 3:45 PM
    How can we manage an error if the data do not pass some validation criteria at the server ? Can we return such errors to an id using something like
    hx-errors
    ?
  • g

    green-activity-6102

    10/26/2022, 3:48 PM
    the server should be doing it's own validation on the submitted data irrespective of what the frontend is submitting -- never trust user submitted data. If your form is posting validation criteria then the user could have manipulated that criteria before submission to exploit your validation. validate server-side and swap the entire form using HTMX with the errors rendered inline on the fields, where applicable
  • g

    green-activity-6102

    10/26/2022, 3:53 PM
    > do not pass some validation criteria at the server maybe i misunderstood this statement -- perhaps you're using the word "pass" to mean that the data validation succeeds Any case the other part of my response is the same, probably easiest to re-render the entire form (with errors inline) and swap it back into the dom using HTMX
  • t

    thankful-apartment-66679

    10/26/2022, 3:58 PM
    ☝🏻 same answer applies
  • b

    boundless-leather-51644

    10/26/2022, 4:01 PM
    So the idea is to return the errors displayed as a bullet list by example of red text (one line per error type) after the Form tag and if the process succeeded to return a message like
    claim id xxx created
  • b

    boundless-leather-51644

    10/26/2022, 4:03 PM
    Rendering the whole HTML Form + errors as response could not be so easy and will need to duplicate the HTML
  • t

    thankful-apartment-66679

    10/26/2022, 4:04 PM
    that definitely sounds like a decent way to do it. you'd iterate through the errors for each form field in your server-side templating engine, printing them to a new list item for each one
  • t

    thankful-apartment-66679

    10/26/2022, 4:05 PM
    you should be able to avoid duplicating the HTML by using a template for the form on the server side and conditionally displaying things depending on the context of the request
1...871872873...1146Latest