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

    proud-librarian-99598

    05/13/2023, 1:17 PM
    I have a Java version that I explain in this blog post: https://www.wimdeblauwe.com/blog/2021/10/04/todomvc-with-thymeleaf-and-htmx/
  • m

    mysterious-toddler-20573

    05/13/2023, 1:33 PM
    I think that's a great idea
  • q

    quick-lamp-41411

    05/13/2023, 1:34 PM
    Just pick Forth
  • b

    bitter-machine-55943

    05/13/2023, 1:36 PM
    Just checked, and yes, QBasic has networking (sort of)
  • a

    astonishing-oil-69230

    05/13/2023, 1:48 PM
    for whom it may interest.. i solved that problem changing the event to "htmx:beforeSwap" and setting "detail.shouldSwap" to "false" when the status code is different from 200
  • c

    clean-piano-67951

    05/13/2023, 1:49 PM
    Hey! Is there any way to conditionally swap. so for example; I have a form. When the form is submitted, if the server returns status code 400, it replaces the element X but if the server returns 200, it replaces the element Y. Would this be possible? Thanks
  • q

    quick-lamp-41411

    05/13/2023, 1:50 PM
    You could use the
    HX-Reswap
    header
  • q

    quick-lamp-41411

    05/13/2023, 1:50 PM
    Err,
    HX-Retarget
    rather
  • q

    quick-lamp-41411

    05/13/2023, 1:52 PM
    We use it with middleware to retarget any non-2xx responses to populate an error modal
  • c

    clean-piano-67951

    05/13/2023, 1:52 PM
    Oh great!
  • c

    clean-piano-67951

    05/13/2023, 2:12 PM
    Okay so weird; when the status code is 200, it works and replaces the correct element. However, when the status code is 400, nothing happens and the form stays the way it is (the Console shows BAD request)
  • q

    quick-lamp-41411

    05/13/2023, 2:21 PM
    By default HTMX only deals with 200 responses
  • b

    bland-coat-6833

    05/13/2023, 2:25 PM
    Are you changing your non-2xx responses to a 2xx response plus a
    Hx-Retarget
    header?
  • q

    quick-lamp-41411

    05/13/2023, 2:25 PM
    Yeah
  • q

    quick-lamp-41411

    05/13/2023, 2:30 PM
    Takes care of things like unhandled errors, validation issues etc. by replacing the 4xx or 5xx response with a 2xx with a HX-Retarget and a server-rendered modal
  • g

    great-cartoon-12331

    05/13/2023, 9:10 PM
    or you could keep 4xx/5xx codes for errors (idiomatic HTTP) and write a tiny bit of custom JS to swap in their error messages on the page
  • g

    great-cartoon-12331

    05/13/2023, 9:10 PM
    or even get htmx to do it
  • l

    late-king-98305

    05/13/2023, 10:01 PM

    https://cdn.discordapp.com/attachments/725789747212976259/1107065139808714923/image.png▾

  • l

    limited-teacher-83117

    05/14/2023, 1:38 AM
    I do this, and it's super reasonable, but I have occasionally wondered if there's some idiomatic way to make that functionality available in a more declarative way
    Copy code
    js
    document.addEventListener('DOMContentLoaded', function () {
      document.body.addEventListener('htmx:beforeSwap', function (evt) {
        const status = evt.detail.xhr.status
        if (status === 400 || status === 500) {
          // Stops the error from logging in the console
          evt.detail.isError = false
    
          // Create an error dialog box
          const errorDialog = document.createElement('div')
          errorDialog.classList.add('error-message')
          errorDialog.innerText = evt.detail.serverResponse
          errorDialog.setAttribute('onclick', 'this.remove()')
    
          // Get the nav and place the element after it
          const nav = document.querySelector('.site-nav')
          nav.insertAdjacentElement('afterend', errorDialog)
          errorDialog.scrollIntoView()
        }
      })
    })
  • l

    limited-teacher-83117

    05/14/2023, 1:41 AM
    I also think we should spotlight the highlight the 204 thing in the notes of
    hx-delete
    specifically, because it tripped me up the first time and I see it in the discord occasionally: https://htmx.org/attributes/hx-delete/
  • g

    great-cartoon-12331

    05/14/2023, 1:43 AM
    mine:
    Copy code
    javascript
    
      // 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>`;
      });
  • g

    great-cartoon-12331

    05/14/2023, 1:44 AM
    i have some CSS that displays
    #toast.error
    and keeps it fixed in place
  • g

    great-cartoon-12331

    05/14/2023, 1:50 AM
    and all my page templates include the
    #toast
    (hidden by default)
  • m

    mysterious-toddler-20573

    05/14/2023, 2:09 AM
    “We”
  • l

    limited-teacher-83117

    05/14/2023, 2:10 AM
    I didn't mean to be presumptuous! Sorry for the phrasing, just trying to say "I'd be willing to do it"
  • l

    limited-teacher-83117

    05/14/2023, 2:29 AM
    This is slick, thanks for sharing
  • g

    great-cartoon-12331

    05/14/2023, 2:30 AM
    np. i've been meaning to write about some htmx tricks and patterns that i've been picking up along the way. blog post formulating.
  • m

    mysterious-toddler-20573

    05/14/2023, 2:34 AM
    😀 I’m just joshing you all good. Would love docs improvements!
  • l

    limited-teacher-83117

    05/14/2023, 2:35 AM
    gotta be weird when a lot of people have contributed to (and start to feel some ownership of) a very particular vision that you've been formulating for a long time
  • a

    adventurous-ocean-93733

    05/14/2023, 11:04 AM
    With this sort of thing I really like “We”, eg “We should [change/add/update]…” it’s great, providing what you actually mean is “I will do a PR to [change/add/update]…”
1...112811291130...1146Latest