https://htmx.org logo
Join Discord
Powered by
# 🔥-django-htmx
  • h

    hundreds-camera-24900

    04/06/2022, 6:18 PM
    but every other field should filter on change?
  • h

    hundreds-camera-24900

    04/06/2022, 6:19 PM
    what do you currently have for your hx-trigger
  • h

    hundreds-camera-24900

    04/06/2022, 6:19 PM
    https://htmx.org/attributes/hx-trigger/
  • c

    careful-dusk-95314

    04/08/2022, 6:37 AM
    The solution i can think of: Listen the event when datetimepicker is being closed, in this listener do an hx-get request
  • e

    eager-lighter-51415

    04/08/2022, 4:30 PM
    Thanks that's what I did.
  • f

    few-vegetable-15970

    04/09/2022, 12:49 AM
    https://dev.to/joashxu/responsive-table-with-django-and-htmx-1fob (also posted in #909436816388669530)
  • f

    few-vegetable-15970

    04/09/2022, 12:51 AM
    This puts
    tables2
    to a completely different level!
  • g

    great-florist-75481

    04/09/2022, 5:37 AM
    Ho, someone has already managed to load a datatable with htmx in django, I haven't done it yet, I read somewhere that with htmx.process() but I don't know how to apply it to the datatable
  • p

    powerful-eye-47205

    04/12/2022, 10:58 PM
    Is it expected behavior that HTMX requests should fail to handle responses with >= 400 status codes? I'm trying to render a login form with re-populated form values and a "Failed authentication" message. It works great (from Express) with
    res.render('/my/handelbars/partial', { myValues })
    -- but if I include the 403 status, it fails to swap out the form completely (just doesn't swap anything as though the request failed). Only difference is changing above to:
    res.status(403).render('/my/handelbars/partial', { myValues })
    -- How can kick back a form with errors and an appropriate status code?
  • m

    mysterious-toddler-20573

    04/12/2022, 11:00 PM
    https://htmx.org/docs/#modifying_swapping_behavior_with_events
  • p

    powerful-eye-47205

    04/12/2022, 11:05 PM
    Oh that helps -- at least now I understand why it's happening. I still feel like I'm not getting something though. I have to write a separate JS block to allow for "forms-with-errors" to be displayed with correct status code? Perhaps I'm approaching this wrong. I really wish there some examples out there of basic CRUD patterns. I so love this concept but I'm struggling to figure out the basics.
  • m

    mysterious-toddler-20573

    04/12/2022, 11:06 PM
    we treat 400 response codes as errors that will not swap, which is usually what you want. Unfortunately there isn't a spec on HTTP status codes we can follow, so we paint with a broad brush and allow users to override the defaults we picked with a bit of scripting.
  • m

    mysterious-toddler-20573

    04/12/2022, 11:07 PM
    I agree a "CRUD for X" where X is "django, flask, php, etc." would be great
  • h

    hundreds-camera-24900

    04/12/2022, 11:10 PM
    is this perhaps not a django form? Django will return a form response as a 200 if it's invalidates
  • p

    powerful-eye-47205

    04/12/2022, 11:10 PM
    Actually, even higher level than that (your patented HOWL stack 😜 ) -- just a guide to understand the basic pattern to submit a form, handle success and redirect, or repopulate form with errors and status code. Figuring out the backend part can be left to the user. I just need to understand the pattern.
  • m

    mysterious-toddler-20573

    04/12/2022, 11:11 PM
    can you respond w/ a non 403?
  • m

    mysterious-toddler-20573

    04/12/2022, 11:11 PM
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
  • h

    hundreds-camera-24900

    04/12/2022, 11:11 PM
    here's some example templates: https://github.com/adamchainz/django-htmx/tree/main/example/example/templates
  • p

    powerful-eye-47205

    04/12/2022, 11:11 PM
    @hundreds-camera-24900 Maybe I'm being pedantic but submitting a login form with bad credentials feels like it should be a 403 and not a 200.
  • h

    hundreds-camera-24900

    04/12/2022, 11:12 PM
    no, a 403 means the request is denied
  • h

    hundreds-camera-24900

    04/12/2022, 11:12 PM
    you have an allowed request with data about the failed attempt
  • m

    mysterious-toddler-20573

    04/12/2022, 11:12 PM
    you are welcome to do that, but you'll need to teach htmx what that means unfortunately
  • p

    powerful-eye-47205

    04/12/2022, 11:13 PM
    hmmmm.... Okay, that sounds reasonable. Maybe I just need to send 200's and get on with my life 🙂
  • m

    mysterious-toddler-20573

    04/12/2022, 11:13 PM
    Copy code
    js
    document.body.addEventListener('htmx:beforeSwap', function(evt) {
        // render 403's for login failures
        if(evt.detail.xhr.status === 403){
            evt.detail.shouldSwap = true;        
        }
    });
  • h

    hundreds-camera-24900

    04/12/2022, 11:14 PM
    It's a little tricky because you're expressing application level behavior in an http status code
  • h

    hundreds-camera-24900

    04/12/2022, 11:14 PM
    rest as a structure is cool because it mixes the two
  • m

    mysterious-toddler-20573

    04/12/2022, 11:14 PM
    I am not doctrinaire about response codes and have seen lots of people do lots of different things so... pluggable
  • p

    powerful-eye-47205

    04/12/2022, 11:14 PM
    can you tell I'm coming from a REST API background? 😉
  • h

    hundreds-camera-24900

    04/12/2022, 11:14 PM
    yes 🙂
  • m

    mysterious-toddler-20573

    04/12/2022, 11:15 PM
    we are inventing the future of HTML hypermedia here folks, let's give ourselves some leeway!
1...565758...100Latest