title: select 2 widget validation with j query in yii2?
body: <p>so i have written a code for select field and i am using yii2 here is my code </p>
  
  <pre><code> &lt;?= $form-&gt;field($model, 'primaryfield')-&gt;widget(Select2::classname(), ['data' 
     =&gt; $listData, 
     'options' =&gt; ['placeholder'=&gt;'Select', 'multiple' =&gt; 
     false,'required'=&gt;true], 'pluginOptions' =&gt; ['tags' =&gt; false, 'tokenSeprators' 
    =&gt; [',', ' '], 'maximumInputLength' =&gt; 20], ],])-&gt;label(false); ?&gt;
  </code></pre>
  
  <p>i want to validate it by using jquery validate plugin i have tried so far validation rules </p>
  
  <pre><code>$('form').validate({
  
  
  errorClass:'help-block help-block-error',
  
  errorPlacement: function(error, element) {
  
  if(element.attr("name") == "TestModel[primaryfield]" )
  {
      error.insertAfter(".error_message2");
  }
  else
        error.insertAfter(element);
   },
  
         rules: {
      'TestModel[email]': {
      required:true,
     email: true 
    },
  
   'TestModel[name]':
   {
    required:true,
  },
  
  'TestModel[primaryfield]':
   {
     required:true
   }
  
   },
  </code></pre>
  
  <p>my email and name getting validated but select2 field(primary field is not getting validate ) i want to apply validation rules only if anyone can give me solutions</p>