This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

lucas.sanner54070
lucas.sanner54070

Here is my form:

{{ form_ajax('onFilterMembers', {flash: ''}) }}

    <select name="licence_type" class="form-control" data-request="onFilterMembers" id="licence-type">
       <option value="licence_a">Licence A</option>
       <option value="licence_b">Licence B</option>
       <option value="licence_c">Licence C</option>
    </select>

    ...

{{ form_close() }}

Now whenever I change the select list the onFilterMembers handler is called twice. Why ?
Note: I checked for a duplicate {% framework extras %} somewhere but I only got one in my layout.

lucas.sanner54070
lucas.sanner54070

I think I've identified the issue. On my page I use Select2

<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>

If I remove these 2 lines the handler is called only one time as expected.
Now what's the problem with Select2 and how can I solve this ?

lucas.sanner54070
lucas.sanner54070

Ok I got it.
I used

$('#mySelect').select2().trigger('change');   

instead of

$('#mySelect').val(null).trigger('change');
daftspunky
daftspunky

Nice! Thanks for sharing your solution

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.