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

    hundreds-camera-24900

    11/11/2021, 2:30 PM
    I only actually render the body tag in the situations where I expect the page to be fully swapped out
  • h

    hundreds-camera-24900

    11/11/2021, 2:30 PM
    so treat the body tag always as an oob swap targeting the body
  • h

    hundreds-camera-24900

    11/11/2021, 2:30 PM
    since I render fragments elsewise
  • h

    hundreds-camera-24900

    11/11/2021, 2:30 PM
    I didn't try that though
  • h

    hundreds-camera-24900

    11/11/2021, 2:31 PM
    that would be more generalizeable though because I'd define once in base.html and never need to alter for a given view
  • c

    careful-room-54859

    11/12/2021, 8:20 PM
    Hi everyone, I am trying to do the following:
    Copy code
    html
    <form id="frmUpdate" method="POST" enctype="multipart/form-data"
      hx-post="{% url 'products:update' product.id %}" 
      hx-target="#viewport"
      hx-swap="innerHTML"
      hx-push-url="true"
      hx-indicator="#content-loader"
      >
      {% csrf_token %}
      {% crispy form form.helper %}
      <div class="flex justify-end gap-3">
        <a hx-get="{{ product.get_list_url }}" 
          hx-target="#viewport"
          hx-swap="innerHTML"
          hx-push-url="true"
          hx-indicator="#content-loader"
          class="intro-x px-3 py-2 cursor-pointer">
          Cancel
        </a>
        <button class="intro-x text-white bg-blue-500 hover:bt-blue-600 px-3 py-2 rounded-md"
          type="submit"
          form="frmUpdate">
          Save
        </button>
      </div>
    </form>
  • c

    careful-room-54859

    11/12/2021, 8:20 PM
    However, when ever I try to update the form....it validates as though it were empty...
  • c

    careful-room-54859

    11/12/2021, 8:22 PM
    I can see in the
    clean
    function on my ProductForm class that it is as well. What has me scratching my head is that I can see the POST in the Network tab in the debugger and it shows the data properly.....
  • c

    careful-room-54859

    11/12/2021, 8:22 PM
    Am I missing something?
  • m

    mysterious-toddler-20573

    11/12/2021, 8:23 PM
    is it expecting the
    multipart/form-data
    encoding?
  • c

    careful-room-54859

    11/12/2021, 8:24 PM
    It is set as show above....
  • m

    mysterious-toddler-20573

    11/12/2021, 8:26 PM
    feels like an encoding issue to me (sorry, not a django expert)
  • c

    careful-room-54859

    11/12/2021, 8:27 PM
    Yeah, it is strange. I noticed I only had the FORM
    enctype
    set so I added
    hx-enctype="multipart/form-data"
    but it still fails.....
  • c

    careful-room-54859

    11/12/2021, 8:32 PM
    @User I saw another post that stated they were running into the same issue. Once I switched to
    1.5.0
    of htmx, it started working...
  • c

    careful-room-54859

    11/12/2021, 8:35 PM
    Okay, I read further down....you need to change the
    hx-enctype
    to
    hx-enctype="text/x-www-form-urlencoded"
    and it works fine.
  • c

    careful-room-54859

    11/12/2021, 8:36 PM
    In Django, for regular forms, it is expecting:
    enctype="multipart/form-data"
  • c

    careful-room-54859

    11/12/2021, 8:36 PM
    So this can be confusing...
  • c

    careful-room-54859

    11/12/2021, 8:36 PM
    Thanks for helping...Really love power of htmx!!!
  • m

    mysterious-toddler-20573

    11/12/2021, 8:39 PM
    👍 sorry for the confusion
  • m

    mysterious-toddler-20573

    11/12/2021, 8:39 PM
    it's strange that django is generating forms that are encoding using a format it doesn't like
  • m

    mysterious-toddler-20573

    11/13/2021, 3:10 AM
    https://github.com/bigskysoftware/htmx/commit/2d9c49a8a179cbe028a0da2ccf5db3c2bf7fc641
  • h

    hundreds-camera-24900

    11/13/2021, 4:22 PM
    nice
  • h

    hundreds-camera-24900

    11/16/2021, 12:03 AM
    used the header - it does exactly what it says it should
  • h

    hundreds-camera-24900

    11/16/2021, 12:03 AM
    it is a definite improvement over what I was doing before w/ the client side redirect
  • h

    hundreds-camera-24900

    11/16/2021, 12:04 AM
    but I can forsee an issue where I have a view and care about the referring url to make a determination on where to target
  • h

    hundreds-camera-24900

    11/16/2021, 12:04 AM
    I guess I'll just have to deal with that when it happens
  • h

    hundreds-camera-24900

    11/16/2021, 12:47 AM
    sorry if that seems negative
  • h

    hundreds-camera-24900

    11/16/2021, 12:47 AM
    The header is a major improvement and now I can keep global state on the client between form submits and that's really awesome
  • m

    mysterious-toddler-20573

    11/16/2021, 1:19 AM
    not at all, we are all figuring it out. What do you mean "the referring url"?
  • h

    hundreds-camera-24900

    11/16/2021, 1:38 AM
    I have a mixin I've been using that looks at the incoming request and figures out of it's got htmx headers, and if so uses a different template
1...171819...100Latest