title: What is invalid about my form with jquery .valid() failing?
body: <p>I have a simple form and I validate it, but then I check to see if it's valid and it is always invalid. How can I check to see what is invalid about my form? If I swap out the razor code with html for the text box it seems to work. I posted the rendered razor code below.</p>
  
  <p>Here is my form - </p>
  
  <pre><code> @using (Html.BeginForm("Search", "Home", FormMethod.Post, new { id = "MyForm", name = "MyForm" }))
      {
          &lt;div class="form-group"&gt;
              @Html.TextBoxFor(model =&gt; model.SearchQuery, new { @class = "form-control", name = "FullAddress", id = "FullAddress" })
              @Html.ValidationMessageFor(model =&gt; model.SearchQuery, "", new { @class = "text-danger" })
  
          &lt;/div&gt;
          &lt;button type="submit" class="btn btn-default"&gt;Search&lt;/button&gt;
      }
  </code></pre>
  
  <p>And here is my script. It displays a alert box every time I hit the submit button and this line is checked</p>
  
  <pre><code>if (!$('#MyForm').valid()) {
              alert('Invalid Form!');
  
  
  
  $(document).ready(function () {
      if ($('#MyForm').exists()) {
  
          // Enable jQuery Validation for the form
          //$("#MyForm").validate({ onkeyup: false, onfocusout: false });
          $("#MyForm").validate();
  
  
  
      var errors = validator.errors(); //get the error elements, the actual labels
      var errors1 = validator.invalidElements();
  
          // Add validation rules to the FullAddress field
          $("#FullAddress").rules("add", {
              fulladdress: true,
              required: true,
              messages: {
                  fulladdress: "Google cannot locate this address."
              }
          });
  
          // This function will be executed when the form is submitted
          function FormSubmit() {
              $.submitForm = true;
              if (!$('#MyForm').valid()) {
                  alert('Invalid Form!');
  
                  return false;
              } else {
                  if ($("#FullAddress").data("IsChecking") == true) {
                      $("#FullAddress").data("SubmitForm", true);
                      return false;
                  }
  
                  alert('Form Valid!  Submit!');
                  // return true;   // Uncomment to submit the form.
                  return false;     // Supress the form submission for test purpose.
  
              }
          }
  
          // Attach the FormSubmit function to the Submit button
          if ($('#Submit').exists()) {
              $("#Submit").click(FormSubmit);
          }
  
          // Execute the ForumSubmit function when the form is submitted
          $('#MyForm').submit(FormSubmit);
      }
  });
  
  // Create a jQuery exists method
  jQuery.fn.exists = function () { return jQuery(this).length &gt; 0; }
  
  
  function LocationValidator(value, element, paras) {
    ///do stuff here
  }
  
  $.validator.addMethod("location", LocationValidator);
  
  $.validator.unobtrusive.adapters.addBool("location");
  
  $.validator.setDefaults({
      onkeyup: false,
      onfocusout: false
  });
  </code></pre>
  
  <p>The invalid part of my form is coming from the searchquery textbox. If I change the html to the line below the form passes as valid. </p>
  
  <pre><code>&lt;input type="text" id="SearchQuery" name="SearchQuery"  class="form-control"/&gt;
  </code></pre>
  
  <p>Here is what the rendered razor code looks like that is failing my form validation check</p>
  
  <pre><code>&lt;input class="form-control" data-val="true" data-val-location="The location cannot be determined" data-val-required="The Location field is required." id="SearchQuery" name="SearchQuery" type="text" value="" /&gt;
  </code></pre>