Manually triggered select event does not send event details

Viewed 38

I am attemping to trigger the on select event handler by triggering the select event however when the event is triggered through code, the event details ((e.params)) is left undefined unlike when the select event is actually triggered by a manual selection

Is there any way to get the event details when trigger('select2:select') is used?

function filterRelevantClientsForSPAWithPreviousValues(){
    let tempSelectedClients = $('select[name=client_id]').val();
    console.log("Past selected client = "+tempSelectedClients);
    $('select[name=client_id]').empty();
    for(var i = 0; i < {{count($spa_client_list)}}; i ++){
      if({!! $spa_client_list !!}[i]['id'] == tempSelectedClients){
          var newOption = new Option({!!$spa_client_list!!}[i]['name'], {!!$spa_client_list  !!}[i]['id'], true, true);
          $('select[name=client_id]').append(newOption).trigger('change').trigger('select2:select');
      }
      else{
          var newOption = new Option({!!$spa_client_list!!}[i]['name'], {!!$spa_client_list  !!}[i]['id'], false, false);
          $('select[name=client_id]').append(newOption).trigger('change');
      }
    }
}

Event Handler

   $('select[name=client_id]').on('select2:select', function (e) {
        console.log("on select client 2 event has been triggered");
        console.log(e.params);
    })

Desired outcome enter image description here

Actual results

enter image description here

0 Answers
Related