title: Active Form Ajax Validate Yii2
body: <p>I need the following validation rules on a form via AJAX:
    </p>
  
  <ul>
  <li>The validation of courses only occur if the Dropwn List code is 2, 3, 4. </li>
  <li><p>In this case the Company Name and Address Company fields are required.
  I tried this code for validation model condition nomeempresa. This code for Model validate in case <code>tipoincricao_codigo == 2</code>:</p>
  
  <pre><code>public function rules() {
      return [
          [
              ['nomeempresa'/*,'cnpj','emailempresa','telefonefixoempresa','telefonecelularempresa', 'enderecoempresa', 'bairroempresa', 'cidadeempresa', 'estadoempresa', 'cepempresa'*/],
              'required',
              'when' =&gt; function ($model) {
                  return $model-&gt;tipoinscricao_codigo == 2;
              }, 'whenClient' =&gt; "function (attribute, value) { return $('#tipoinscricao_codigo').val() == 2;}"
          ]
      ];
  }
  </code></pre></li>
  </ul>