After removing the search box in the select2 keyboard, select the option does not work

I am using select2 in my project. According to the design, I delete the search box in selectbox2, but after deleting the search box, the keyboard selection option does not work. Can anyone help me fix this. - Thank

the code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Select2 Template</title>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css">
  </head>
  <style>
    body {
      margin: 0;
      padding: 0;
    }
  </style>

  <body>
    <div>Skills</div>
    <select id="skills" style="width: 200px">
      <option>html</option>
      <option>css</option>
      <option>js</option>
    </select>

    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
    <script>
      $(document).ready(function() {
        $('#skills').select2({
          minimumResultsForSearch: Infinity
        });
      });
    </script>
  </body>
</html>

JS Bin: http://jsbin.com/kipuzet/edit?html,output

+4
source share
1 answer

Instead

$('#skills').select2()

use

$('#skills').select()

That should work.

+1
source

Source: https://habr.com/ru/post/1651141/


All Articles