How to select multiple items from a dropdown, choose these items with a button, and then reload the screen?

Asked

Viewed 67 times

2

In this html code of a Django project how to add a feature that the user will choose how many services they want and click on the button when finished choosing. In this application I can only choose one service at a time, I implemented SELECT2, I already implemented the tag 'Multiple' but I can’t choose more than 2 or more in the dropdown, I click on the service and already save the first value, the names with the services come from the Database. I need to select the services I want and then save them then, because the query continues and goes to another dropdown with vehicles of the service I chose but does not work the search as a whole. But how to do this if when I select 1 service the screen is reloaded because of the onchange event.

HTML

<h3><strong>Serviço</strong></h3>

<select id="servico_cad" name="servico_cad" multiple="multiple" onchange="saveValue(this);this.form.submit();">

        {% for i in servico_cad %}
            
            <option value='{{i}}'>{{i}}</option>

        {% endfor %}
                        
            <option value='Todos'>Todos</option>
</select>

JS
$(document).ready(function() {
            $("#servico_cad").select2({
            closeOnSelect:false
            });

1 answer

1

You only get the last amount because you are requesting a list. In your views, you must use request.GET.getlist('servico_cad') in order to handle the two options chosen.

  • I understood your comment, in my views.py the 'servico_cad' this type POST within an if, pq this 'servico_cad' option is part of a search.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.