title: Yii2 Dependent Autocomplete send Extra Parameters
body: <p>Below are snippets of two Yii2.0 Autocomplete widgets</p>
  
  <pre><code> &lt;?php 
          echo $form-&gt;field($model, 'countryId')-&gt;begin();
          echo Html::activeLabel($model, 'countryId', ["class"=&gt;"control-label col-md-4"]); ?&gt;
         &lt;div class="col-md-5"&gt;
           &lt;?php 
                  $data = Country::find()-&gt;select('countryName as label, id as id')-&gt;asArray()-&gt;all();
                  echo AutoComplete::widget([
                          'name' =&gt; 'countryId',
                          'clientOptions' =&gt; [
                                  'source' =&gt; $data,
                                  'autoFill'=&gt;true,
                                  'minLength'=&gt;'1',
                                  'select'=&gt;"js:function(event,item){\$(\"#countryid\").val(item[1]);})",
  
                               ],
                           'options' =&gt; [
                                  'class' =&gt; 'form-control',
                               ],
                          ]);
              ?&gt;
           &lt;?php echo Html::activeHiddenInput($model, 'countryId'); ?&gt;
           &lt;?php echo Html::error($model, 'countryId', ['class'=&gt;'help-block']); ?&gt;
           &lt;/div&gt;
   &lt;?php echo $form-&gt;field($model, 'countryId')-&gt;end();?&gt;
  </code></pre>
  
  <p>and for State:</p>
  
  <pre><code>    &lt;?php 
          echo $form-&gt;field($model, 'stateId')-&gt;begin();
          echo Html::activeLabel($model, 'stateId', ["class"=&gt;"control-label col-md-4"]); ?&gt;
         &lt;div class="col-md-5"&gt;
           &lt;?php 
                  echo AutoComplete::widget([
                          'name' =&gt; 'countryId',
                          'clientOptions' =&gt; [
                                  'source' =&gt; 'js:function(request, response) {
                                                  \$.getJSON(\"'+Yii::$app-&gt;urlManager-&gt;createUrl("site/get-states")+'\", { country: \$(\"#countryid\").val() }, 
                                                  response);
                                              }',
                                  'autoFill'=&gt;true,
                                  'minLength'=&gt;'1',
                                  'select'=&gt;"js:function(event,item){\$(\"#stateid\").val(item[1]);}",
  
                               ],
                           'options' =&gt; [
                                  'class' =&gt; 'form-control',
                               ],
                          ]);
           echo Html::activeHiddenInput($model, 'stateId');
           echo Html::error($model, 'stateId', ['class'=&gt;'help-block']); ?&gt;
           &lt;/div&gt;
   &lt;?php echo $form-&gt;field($model, 'stateId')-&gt;end();?&gt;
  </code></pre>
  
  <p>My getStates Controller is:</p>
  
  <pre><code>public function actionGetStates(){
      if(Yii::$app-&gt;request-&gt;isAjax &amp;&amp; isset($_GET['term']) &amp;&amp; isset($_GET['country'])) {
          /* term is the default GET variable name that is used by
           / the autocomplete widget to pass in user input
           */
         // \Yii::$app-&gt;response-&gt;format = 
          $name = $_GET['term'];
          $country = $_GET['country'];
  
          // this was set with the "max" attribute of the CAutoComplete widget
          $limit = min($_GET['limit'], 50);
  
          $statesArray = State::find()-&gt;select('stateName as label, id as id')-&gt;where('stateName LIKE :sterm AND countryId=:countryId')-&gt;params([':sterm'=&gt;"%$name%", ':countryId'=&gt; $country])-&gt;all();
  
  
          return $statesArray;
      }
  }
  </code></pre>
  
  <p>This give me an error:</p>
  
  <blockquote>
    <p>TypeError: this.source is not a function</p>
    
    <blockquote>
      <p>this.source( { term: value }, this._response() );</p>
    </blockquote>
  </blockquote>
  
  <p>Please help me to send country Id to my controller. I have also tried extraParams option, but jquery ui doesn’t support that option any more.</p>