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

    fresh-judge-74869

    02/26/2022, 1:18 PM
    and this is my view which updates the two dependent chained dropdowns:
    Copy code
    def company_project_client(request):
        company_pk = request.GET.get("main-company")
        project_qs = Project.objects.filter(company=company_pk)
        clientprofile_qs = ClientProfile.objects.filter(company=company_pk)
        context = {
            "project_qs": project_qs,
            "clientprofile_qs": clientprofile_qs,
        }
        return render(request, "orders/company_project_client.html", context)
    and this is my template
    Copy code
    <div id="id_main-project-client" class="form-group col-md-2">
        <div class="form-group">
            <label for="">Proyecto</label>
            <select name="main-project" class="form-control" id="id_main-project">
                <option value>---------</option>
                {% for project in project_qs %}
                <option value="{{ project.pk }}">{{ project.name|safe }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="form-group">
            <label for="">Cliente</label>
            <select name="main-client" class="form-control" id="id_main-client">
                <option value>---------</option>
                {% for clientprofile in clientprofile_qs %}
                <option value="{{ clientprofile.pk }}">DNI:{{ clientprofile.user.dni|safe }} {{ clientprofile.user.first_name|title|safe }} {{ clientprofile.user.last_name|title|safe }}</option>
                {% endfor %}
            </select>
        </div>
    </div>
  • f

    fresh-judge-74869

    02/26/2022, 2:47 PM
    the error is
    dict_values([['Select a valid choice. That choice is not one of the available choices.'], ['Select a valid choice. That choice is not one of the available choices.']])
  • f

    future-continent-38061

    02/27/2022, 8:50 PM
    I am building a job board and would like to filter jobs by employment type (full time, part time, internship) and employer type (government, company, NGO) at the same time. I had employer type working with hg-get and a view that filters based on a slug. How would you filter that if you just wanted to click buttons, i.e. you click full time and you see all full time jobs, then you click government and you see all full time government jobs. How can I keep the full time filter "active" when I get all government jobs? Further, it would be great to activate multiple filters, i.e. government and NGO jobs etc. I am using htmx and alpinejs but am a beginner and would appreciate any help pointing me in the right direction.
  • g

    gorgeous-airport-54386

    02/27/2022, 9:00 PM
    You would include the filter buttons in the response, so the server would receive the list of filters, and respond with the table + the buttons where the active buttons are checked
  • f

    future-continent-38061

    02/27/2022, 9:06 PM
    That sounds like a good way to do it. How would I send the list of filters to the server? With a form (checkboxes) or is there something simpler or can I send multiple slugs (as I have unique slugs for the categories)?
  • g

    gorgeous-airport-54386

    02/27/2022, 9:07 PM
    Checkboxes are the best way I can think of, hide the checkbox itself and make the label look like a button with CSS
  • f

    future-continent-38061

    02/27/2022, 9:13 PM
    Ok thats what I tried so far, e.g. building a form in my template like that. Do I then need to post the form or how do I link this so that the server knows what to filter?
  • g

    gorgeous-airport-54386

    02/27/2022, 9:14 PM
    You would post the form, yes. Use
    hx-trigger=change
  • g

    gorgeous-airport-54386

    02/27/2022, 9:14 PM
    Change events from the checkboxes will bubble up to the form.
  • f

    future-continent-38061

    02/27/2022, 9:22 PM
    Ok I am getting something like this when I print(request) and print every item in request: b'vollzeit=on&praktikum=on' // which means: full time=on and internship=on How do I access this in my view?
  • g

    gorgeous-airport-54386

    02/27/2022, 9:23 PM
    Google " access form data"
  • f

    future-continent-38061

    02/27/2022, 9:31 PM
    Thats where I am a bit lost. I have built the form in the template so that I can style it easier with Tailwind CSS.... The names of the input fields correspond to the slugs that I would like to filter on. Would I need to build it in forms.py first?
  • g

    gorgeous-airport-54386

    02/27/2022, 9:35 PM
    You need to pass the slugs to your view
  • g

    gorgeous-airport-54386

    02/27/2022, 9:35 PM
    From your controller
  • f

    future-continent-38061

    02/27/2022, 9:42 PM
    These are just four slugs for each filter (employment type and employer type). So I cannot just send them from the template to a view function?
  • g

    gorgeous-airport-54386

    02/27/2022, 9:43 PM
    Someone that actually knows Django needs to answer that
  • f

    future-continent-38061

    02/27/2022, 9:50 PM
    Ok, I will keep researching until then. Thank you so much for your help, @User ! It helped a lot finding/verifying what I need to achieve!
  • c

    calm-ice-23682

    02/27/2022, 10:37 PM
    spotted this today if it's of any use to anyone here github.com/saleor/saleor
  • h

    hundreds-pillow-63494

    02/28/2022, 1:28 AM
    Hi everyone, not sure if you are aware but the site https://htmx-django.com/ is facing a Heroku application error
  • w

    witty-yak-87722

    02/28/2022, 5:50 PM
    This is still happening
  • l

    lemon-battery-11524

    03/01/2022, 7:02 PM
    I've got an element below making a get request on load and on custom event
    Copy code
    <div id="bookings"
         hx-trigger="load, bookingsChanged from:body"
         hx-get="{% url 'upcoming_bookings' %}"
         hx-target="this">
    </div>
    And every time it triggers
    undefined
    is added to the get request like so:
    "GET /dashboard/bookings/upcoming/?undefined=undefined HTTP/1.1" 200 7408
    What's that and how do I get rid of it?
  • h

    hundreds-camera-24900

    03/01/2022, 9:32 PM
    try hx-params='none'
  • h

    hundreds-camera-24900

    03/01/2022, 9:32 PM
    I am wondering if you have a form field under the div?
  • h

    hundreds-camera-24900

    03/01/2022, 9:33 PM
    https://htmx.org/attributes/hx-params/
  • h

    hundreds-camera-24900

    03/01/2022, 9:33 PM
    * is the default so for some reason htmx must think you have something under it
  • l

    lemon-battery-11524

    03/01/2022, 10:57 PM
    that div is not a part of form and there are no other form fields around it. Tried adding
    hx-params='none'
    but it's still the same 🤔
  • h

    hundreds-camera-24900

    03/02/2022, 1:24 AM
    if you added hx-params='none' and it's still there then it's either a bug or outside of htmx
  • h

    hundreds-camera-24900

    03/02/2022, 1:25 AM
    I would double check your global JS and then try to make a demo (https://htmx.org/docs/#creating-demos)
  • h

    hundreds-camera-24900

    03/02/2022, 2:35 PM
    https://adamj.eu/tech/2022/03/02/django-htmx-on-read-the-docs/
  • h

    hundreds-camera-24900

    03/02/2022, 2:35 PM
    https://django-htmx.readthedocs.io/en/latest/
1...535455...100Latest