$(document).on('select2:open',(event) => {
  const searchField = document.querySelector(
    `.select2-search__field[aria-controls="select2-${event.target.getAttribute('data-select2-id')}-results"]`,
  );
  if (searchField) {
     searchField.focus();
  }
});