https://htmx.org logo
Join Discord
Powered by
# πŸ”₯-django-htmx
  • m

    melodic-translator-29773

    12/21/2021, 12:43 AM
    @User thanks for the answer , I have a component to find the items and using javascript create the inputs in the formset and go through it in the view that will receive the data for the form.
  • m

    melodic-translator-29773

    12/21/2021, 12:45 AM
    I am basically understanding that HTMX must handle it at the component level. that is, create a component to edit an item in a list or search for an item
  • m

    melodic-translator-29773

    12/21/2021, 11:03 PM

    https://youtu.be/h9sxlkdMTeAβ–Ύ

    found this tutorial is part of the series of django 3.2
  • b

    broad-baker-92644

    12/22/2021, 4:49 AM
    Can anyone help me figure out what's wrong with the file upload with the progress bar problem? The file is uploaded but the progress bar doesn't show the upload progress properly. It reaches 100% right away no matter how big the file is. The console log shows the evt.detail.loaded always equals evt.detail.total. I think that's why the problem happened. But I don't know how to fix it.
  • b

    blue-gold-89534

    12/22/2021, 1:58 PM
    Hello ... I need some advice on how to render a part of a table using HTMX. I have: - a base template (base.html) which loads HTMX, bootstrap and so on ... - a template for a site, extending base.html and including a table.html - a table.html - this is where the actual table is. I tried it like this:` `
  • b

    blue-gold-89534

    12/22/2021, 1:59 PM
    But now the page only loads table.html without anything else
  • b

    blue-gold-89534

    12/22/2021, 2:48 PM
    (I know why only the table is loaded - what I do not know is, how to decide to send the "full site" and when to decide only the "partial" is enough)
  • g

    gorgeous-airport-54386

    12/22/2021, 2:48 PM
    For that, you can check if the
    HX-Request
    header exists on the response.
  • g

    gorgeous-airport-54386

    12/22/2021, 2:49 PM
    If it exists, the request is being made by htmx, and you can send the partial.
  • b

    blue-gold-89534

    12/22/2021, 3:08 PM
    how do you usually do that? I went for
    Copy code
    if "hx-request" in request.headers.keys()
        if headers.request["hx-request"] == True: ...
    - is there a shorter approach?
  • g

    gorgeous-airport-54386

    12/22/2021, 3:10 PM
    I'm not actually a Django person but if I remember Python correctly,
    if "hx-request" in request.headers
    should be enough
  • b

    blue-gold-89534

    12/22/2021, 3:16 PM
    ok ... so far that already helped me a bunch πŸ™‚ Thanks!
  • m

    mysterious-toddler-20573

    12/22/2021, 3:16 PM
    https://pypi.org/project/django-htmx/
  • m

    mysterious-toddler-20573

    12/22/2021, 3:16 PM
    this might be useful
  • b

    blue-gold-89534

    12/22/2021, 3:17 PM
    yes I used that before, but I did not see it in some of the other projects, so I thought I will not include it.
  • b

    blue-gold-89534

    12/22/2021, 3:17 PM
    It's kind of actually doing exactly that, right.
  • m

    mysterious-toddler-20573

    12/22/2021, 3:17 PM
    yep, just makes it nicer to read
  • m

    mysterious-toddler-20573

    12/22/2021, 3:17 PM
    "just"
  • b

    blue-gold-89534

    12/22/2021, 3:23 PM
    so .. another questiion. I now have my table in one html (partial) and I include it in another html (full). when I click on the pagination I (successfully, now thanks to @User ) it with the next page ... can I do it like this: {% include "talbe.hmtl" $} and in table.html I have a: ... (it works, just want to know if it is smart to do it that way)
  • b

    blue-gold-89534

    12/22/2021, 3:23 PM
    <main id="main">{% include "table.hmtl" %} </main>
    and in table.html I have a:
    <nav hx-boost="true"  hx-target="#main"  hx-swap="outerHTML"> ... </nav>
  • b

    blue-gold-89534

    12/22/2021, 3:24 PM
    probably better to use
    swap=innerHTML
    ?
  • b

    blue-gold-89534

    12/22/2021, 3:24 PM
    otherwise the will be killed
  • a

    abundant-breakfast-94967

    12/22/2021, 11:35 PM
    Hi - I've been hacking on django-htmx for a bit and building a filter setup. I'm totally new to UI development (long time backend dev) so apologies if my question has obvious answers. I'm trying to add a form that allows a user to add filter context to list a bunch of entities. I have ZIP/address input and then have a category/sub-category filter. The category filter has say 13 options and thinking of doing this with a simple dropdown. However, the sub-category can have ~20-100 options that are dependent for each parent category (think traversing down a tree from root to children). Based on the parent category selected, I want to be able to then give the user type-ahead for the 20-100 sub-category children with a particular parent category. I've been doing something janky with a text input and datalist where I am using htmx to swap out my datalist html based on the parent category selected. This works OK but it's janky in that if I pick a different parent category it doesn't clear my datalist. Should I be reaching for either another all in one widget/tool, should I be looking at something like alpine to add more state around this stuff or is swapping out the datalist in htmx too little and I should be swapping out the entire form?
  • b

    bland-coat-6833

    12/23/2021, 12:47 PM
    So with Django-htmx you can test for
    request.htmx
    in your template. I use that to decide whether to extend from a base template. Eg in your example, if
    request.htmx
    is false then you would extend from index.html. If it’s true then don’t extend and just return table.html
  • b

    bland-coat-6833

    12/23/2021, 12:48 PM
    That was for @blue-gold-89534 - discord didn’t tag the reply properly,sorry
  • b

    blue-gold-89534

    12/23/2021, 12:56 PM
    yes this is clear to me, I use that already.
  • a

    abundant-breakfast-94967

    12/23/2021, 8:19 PM
    On my above question https://stackoverflow.com/questions/65655436/how-to-have-nested-select-dropdin:#django-htmx%20formown-that-will-fetch-differently-for-the-main-list Looking at this answer. This works if I use basic html. However, does anyone have examples of using tom-select or select2 to get more robust selects with typeahead but be able to swap out from server-side
  • a

    abundant-breakfast-94967

    12/23/2021, 8:26 PM
    Ended up getting something working but it's kind of janky (since it flashes when the form is reloaded) The parent and child select
    Copy code
    The
        <select 
          class="h-full text-lg bg-gray-200 rounded" 
          name="insurance"
          hx-get="/app/plan_options"
          hx-target="#plan-select-holder"
          hx-trigger="change"
          hx-swap="innerHTML"
        >
          <option class="tex-gray-500" select value="">Insurance Provider</option>
          <option value="aetna">Aetna</option>
          <option value="united">United</option>
          <option value="bcbs">Blue Cross Blue Shield</option>
        </select>
        <div id="plan-select-holder"></div>
    HTML that is returned by plan options
    Copy code
    <select id="plan-select">
      {% for opt in options %}
        <option value="{{opt}}">{{opt}}</option>
      {% endfor %}
    </select>
    <script>
        new TomSelect('#plan-select',{
            plugins: ['dropdown_input'],
        });
    </script>
  • b

    blue-gold-89534

    12/23/2021, 10:54 PM
    by the way: https://github.com/rg3915/django-htmx-tutorial I think this is a quite nice tutorial, unfortunately I have to decipher some of the comments via google translate from spanish to english, but it shows a lot of htmx magic interacting with django - maybe everybody knows it already, but I like it quite a lot (although it does not make use of some htmx possibilities like adamchainz django-htmx git shows)
  • a

    abundant-breakfast-94967

    12/23/2021, 11:11 PM
    I really wish that was in english lol
1...262728...100Latest