title: js active form validation in yii2
body: <p>I have a active form and I am trying to validate it using the script written below : </p>
  
  <pre><code>jQuery("#form").yiiActiveForm("submitForm");
  </code></pre>
  
  <p>The problem is, the script always returns false. But when I call it second time with some delay, it returns true.</p>
  
  <pre><code>jQuery("#form").yiiActiveForm("submitForm");
  setTimeout(function () {
  if (jQuery("#form").yiiActiveForm("submitForm")) {
          //ajax call...    
      }
  }, 300);
  </code></pre>
  
  <p>My question is, how does validation works in yii2 ?
  And is there a better way to validate active forms in js?</p>
  
  <p>When I use </p>
  
  <pre><code>jQuery("#form").yiiActiveForm("submitForm");
  </code></pre>
  
  <p><em>beforeSubmit</em> handler is called.</p>
  
  <pre><code>$('#form').on('beforeSubmit', function (e) {
      alert('message');
  });
  </code></pre>
  
  <p>Does <em>beforeSubmit</em> automatically validates the form?</p>