title: jQuery validation plugin - not setting focus in Webkit browsers
body: <p>Hope you can help.. am using <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">http://bassistance.de/jquery-plugins/jquery-plugin-validation/</a> in an ASP.NET MVC project on an address entry form.</p>
  
  <p>I'm really trying to find out whether there is some kind of conflict between the Validation Plugin and webkit browsers (e.g. Safari, Chrome), or between jQuery and webkit browsers, before I embark on a bug-hunting mission (although I've already wasted several hours and got nowhere :( )</p>
  
  <p>We've got an MVC master page containing, in the &lt;head&gt; section:</p>
  
  <pre><code>$("#deliveryAddressForm, #paymentForm").validate({
  
      showErrors: function(errorMap, errorList) {
  
          if (errorList.length &gt; 0) {
  
              var form = errorList[0].element.form;
  
              if (form.id == "deliveryAddressForm") {
                  displayErrorMessage("&lt;%= CheckoutController.ERROR_MESSAGE_DELIVERY_ADDRESS %&gt;");
              }
              else if (form.id == "paymentForm") {
                  displayErrorMessage("&lt;%= CheckoutController.ERROR_MESSAGE_ORDER %&gt;");
              }
  
              $("span.error").remove(); // remove server-side validation error messages
          }
          this.defaultShowErrors();     // call overridden showErrors
      },
      onkeyup: function(element) {                     // on keyup if form now valid remove banner error message
          if ($("label.error").length &gt; 0) {           // If some client-side errors currently displayed
              if ($("#" + element.form.id).valid()) {  // validate form, then if no errors remain
                  $("#errorMessage").remove();         // remove banner error message
              }
          }
      }
  });
  </code></pre>
  
  <p>The displayErrorMessage() function looks like this:</p>
  
  <pre><code>function displayErrorMessage(msg) {
      $("#errorMessage").remove();
      $("#userMessages").append('&lt;div id="errorMessage"&gt;' + msg + '&lt;/div&gt;');
  }
  </code></pre>
  
  <p>where #userMessages is a div at the top of the page to display an error message summary as a banner.  (e.g. 'There is a problem with your delivery address.  Please correct the errors below')</p>
  
  <p>This all works fine in all the browsers, except the webkit browsers (e.g. Safari, Chrome).</p>
  
  <p>In these browsers, the Validation Plugin, after performing validation, should set the input focus to the first invalid field on the page.  It doesn't do this in webkit browsers.  In Safari, for instance, the thick blue box appears around the correct field, but the cursor does not appear in the field, and it does not have focus.</p>
  
  <p>After a failed attempt to submit the form - say the phone number was blank - the client side error messages appear as expected.  When you start typing in, say, the phone number field, the 'onkeyup' code calls valid() (which re-validates the form and returns true if it is valid) finds that it is no longer invalid (blank), and should remove the error message summary banner (#userMessages). </p>
  
  <p>Although all the browsers correctly remove the banner, in Safari the field loses focus, even though the thick blue box remains on the field.  So subsequent keystrokes are lost and you have to click back onto the phone number field to continue.</p>
  
  <p>Hope you can help as I'm at a loss!</p>
  
  <p>Thanks in advance</p>
  
  <p>Ed</p>