1

I have seen many topics about select2 trigger but I can't find a solution to my case. I want my select2 filter to load some data immediately when a user click on it.

Is that possible ? I tried to do it, it only works when a another option is selected, not at the moment when the select is clicked.

Thanks !

For example, this works for change trigger :

$('#id_station').on('select2:select', function (e) {
   alert();
});
AjaxLoser
  • 31
  • 1
  • 9

1 Answers1

1

I am using select2 version 4.0.3 and the following code is working for me

   $('#id_station').on('select2:select', function (e) {
   alert();
});


please check below example

(function($){
  $('#id_station').select2();
  
 
  $('#id_station').on('select2:select', function (e) {
   alert("Selected");
});

})(jQuery);
body{
  font-family: sans-serif;
}

.select2{
  width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>

<select class="select2" id="id_station">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3" selected>Option 3</option>
  <option value="4">Option 4</option>
  <option value="5">Option 5</option>
  <option value="6">Option 6</option>
  <option value="7">Option 7</option>
</select>
Manasi
  • 765
  • 6
  • 17
  • @AjaxLoser : you should accept and vote up the answer if it helps you, so that others can find it helpful. – Manasi Aug 02 '18 at 06:52