Source du gabarit : frags/search_full.html

{% load i18n static %}
<section class="research__bloc">
    <div class="research research--full wrapper--centered">
        <form action="{% url 'product_search' %}" method="GET" class="column column--spaced">
            <div class="research__field">
                <span class="research__btn"></span>
                  <select id="select_mun" class="input--select2--d-placeholder"  data-placeholder="Choisis ta Commune ..." onchange="if (this.selectedIndex) window.location.href = this.value;">
                    <option>

                    </option>
                  </select>
            </div>
        </form>
    </div>
</section>

<script>
    fetch('/api/main/get_municipalities')
        .then(resp => resp.json())
        .then( json => {
            // retrieve municipalities
            const selectMun = document.getElementById('select_mun');

            for (let municipality of json){
                var opt = document.createElement('option');
                opt.value = `/commune/${municipality.name}/${municipality.postal_code}`;
                opt.innerHTML = `${municipality.name} - ${municipality.postal_code}`
                selectMun.appendChild(opt);
            }
        })
</script>