title: Yii2 - How can I add a search in Dropdownlist Widget
body: <p>Good day!</p>
  
  <p>How can I add a <strong>search</strong> on a <strong>dropdownlist</strong>?</p>
  
  <p>I want a dropdown search like the <strong>Select2 widget</strong>.</p>
  
  <p>Dropdownlist:</p>
  
  <pre><code>&lt;?= $form-&gt;field($modelRis, "[{$i}]lib_item_item_id")-&gt;dropDownList(
  ArrayHelper::map(LibItem::find()-&gt;orderBy('item_description')-&gt;all(), 'item_id', 'item_description'),
  [
      'prompt'=&gt;'Select Item',
      'onchange'=&gt;'
              var tmp = $(this).attr("id");
              var thisId = tmp.split("-");
  
              var tmp2 = "";
              var tmp3 = "";
  
              var sample_id = $(this).val();
  
              $.post( "'.Yii::$app-&gt;urlManager-&gt;createUrl(['online-requisition/listsofunit?item_id=']).'"+$(this).val(),
              function( data ) {
                  $( "#risrequesteditem-"+thisId[1]+"-lib_unit_id").html( data );
  
                  $( "#loop-"+thisId[1]+"-lib_item_item_id").val( sample_id );
  
                  tmp2 = data;
                  tmp3 = tmp2.split("=====");
                  $( "#loop-"+thisId[1]+"-available_stock").val( tmp3[1] );
              });
          ',
      'pluginOptions' =&gt; [
              'allowClear' =&gt; true
      ],
  ])-&gt;label('Item',['class'=&gt;'label-class']); ?&gt;
  </code></pre>
  
  <p>I can't use the select2 widget because the <strong>'onchange'</strong> or this line of code is not supported:</p>
  
  <pre><code>'onchange'=&gt;'
              var tmp = $(this).attr("id");
              var thisId = tmp.split("-");
  
              var tmp2 = "";
              var tmp3 = "";
  
              var sample_id = $(this).val();
  
              $.post( "'.Yii::$app-&gt;urlManager-&gt;createUrl(['online-requisition/listsofunit?item_id=']).'"+$(this).val(),
              function( data ) {
                  $( "#risrequesteditem-"+thisId[1]+"-lib_unit_id").html( data );
  
                  $( "#loop-"+thisId[1]+"-lib_item_item_id").val( sample_id );
  
                  tmp2 = data;
                  tmp3 = tmp2.split("=====");
                  $( "#loop-"+thisId[1]+"-available_stock").val( tmp3[1] );
              });
          ',
  </code></pre>
  
  <p>Thanks...</p>
  
  <p>Updates:</p>
  
  <p>If i'm going to used the select2 widget in order to have a search function during the selection of items there will be a problem.</p>
  
  <p><strong>In the :</strong></p>
  
  <p><strong>first selection</strong> its working:</p>
  
  <p>And the <strong>onchange function</strong> has been working also. And automatically fill all the data in form field (Item no, Unit and StockAvailable) after the selection of item.
  <a href="https://i.stack.imgur.com/7mD7e.jpg" rel="nofollow noreferrer">1st Selection</a></p>
  
  <p><strong>second selection</strong> is not working:
  But I can select an item. Only the jquery function onchange is the problem... 
  <a href="https://i.stack.imgur.com/bvg6J.jpg" rel="nofollow noreferrer">2nd Selection</a></p>
  
  <p>Thanks...</p>