title: Ignoring required's on an entire form using jQuery.Validate()
body: <p>I'm trying to ignore the required validation on an entire form using jQuery validate but can't seem to get it working, this is on an MVC project using an @html helper so I can't add names to the elements to validate, I also cant remove the validation then add it all back using jQuery since not all the fields are required, I'll put my current java below and any help will be much appreciated</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$("body").on("click", ".next", function(e) {
    e.preventDefault();
    var btn = $(this);
    var form = btn.closest("form");
    form.validate({
      rules: {
        required: false
      }
    });
    //check if form is valid
    if (form.valid()) {
      var out = form.validate({
        rules: {
          required: true
        }
      });
      if (form.valid()) {
        alert("valid and complete");
      } else {
        alert("valid but not complete");
      }
    } else {
      showSysMessage("Invalid Data. Please Check the Data in the Highlighted Fields", {
        color: "#FFB347"
      });
    };
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p><b>Edit</b></p>
  
  <p>This validator needs to validate multiple different partials with over 300 fields so using the names of each individual element would be beyond impractical, so I'm wondering if there is a way to validate a form and not validate the required on the inputs, hope this helps</p>
  
  <p><b>Edit 2</b></p>
  
  <p>Im my model I have the fields that are required with a [Required] over them, But I would like stage one on the validation to check if the data entered is valid, If it is it will save these to the database and allow page change, then the second step of the validation needs to check if all the elements that have been set to required in the model have been filled in, and if they have been return that the form has been Completed</p>
  
  <p>Here is a sample of my model</p>
  
  <pre><code>    [Required]
      [Display(Name = "Title")]
      public int? TitleID { get; set; }
  
      [Required]
      [Display(Name = "First Name")]
      public string FirstName { get; set; }
  
      [Display(Name = "Middle Names")]
      public string Middlename { get; set; }
  
      [Required]
      [Display(Name = "Surname")]
      public string Surname { get; set; }
  
      [Required]
      [Display(Name = "Date of Birth")]
      public DateTime? DateOfBirth { get; set; }
  
      [Required]
      [Display(Name = "Nationality")]
      public string Nationality { get; set; }
  
      [Required]
      [Display(Name = "Martial Status")]
      public int? StatusMaritalID { get; set; }
  
      [Required]
      [Display(Name = "NI Number")]
      public string NINumber { get; set; }
  
      [Required]
      [Display(Name = "Have you been known by diffrent names?")]
      public bool? IsKnownByOtherNames { get; set; }
  
      [Required]
      [Display(Name = "Phone Number")]
      public string PhoneNumber { get; set; }
  
      [Required]
      [Display(Name = "Mobile Number")]
      public string MobileNumber { get; set; }
  
      [Required]
      [Display(Name = "Email")]
      public string Email { get; set; }
  </code></pre>
  
  <p>Here is a sample of the controller that gets any filled out data</p>
  
  <pre><code>    model.TitleID = data.TitleID;
  
      model.FirstName = data.FirstName;
  
      model.Middlename = data.Middlename;
  
      model.Surname = data.Surname;
  
      model.DateOfBirth = data.DateOfBirth;
  
      model.Nationality = data.Nationality;
  
      model.StatusMaritalID = data.StatusMaritalID;
  
      model.NINumber = data.NINumber;
  
      model.IsKnownByOtherNames = data.IsKnownByOtherNames;
  
      model.PhoneNumber = data.PhoneNumber;
  
      model.MobileNumber = data.MobileNumber;
  
      model.Email = data.Email;
  </code></pre>
  
  <p>Here is an example of the save controller</p>
  
  <pre><code>                data.TitleID = model.TitleID;
  
                  data.FirstName = model.FirstName;
  
                  data.Middlename = model.Middlename;
  
                  data.Surname = model.Surname;
  
                  data.DateOfBirth = model.DateOfBirth;
  
                  data.Nationality = model.Nationality;
  
                  data.StatusMaritalID = model.StatusMaritalID;
  
                  data.NINumber = model.NINumber;
  
                  data.IsKnownByOtherNames = model.IsKnownByOtherNames;
  
                  data.PhoneNumber = model.PhoneNumber;
  
                  data.MobileNumber = model.MobileNumber;
  
                  data.Email = model.Email;
  </code></pre>
  
  <p>Here is the view being used</p>
  
  <pre><code>&lt;h2&gt;Personal Details&lt;/h2&gt;
  
  &lt;div class="row-fluid"&gt;
      &lt;div class="span3"&gt;
          @Html.LabelFor(x =&gt; x.TitleID)
          @Html.DropDownListFor(x =&gt; x.TitleID, Model.Titles, "-- Please Select --", new { @class = "input-block-level" })
          @Html.LabelFor(x =&gt; x.DateOfBirth)
          @Html.TextBoxFor(x =&gt; x.DateOfBirth, "{0:dd/MM/yyyy}", new { @class = "input-block-level date-picker" })
      &lt;/div&gt;
      &lt;div class="span3"&gt;
          @Html.LabelFor(x =&gt; x.FirstName)
          @Html.TextBoxFor(x =&gt; x.FirstName, new { @class = "input-block-level" })
          @Html.LabelFor(x =&gt; x.Nationality)
          @Html.TextBoxFor(x =&gt; x.Nationality, new { @class = "input-block-level" })
      &lt;/div&gt;
      &lt;div class="span3"&gt;
          @Html.LabelFor(x =&gt; x.Middlename)
          @Html.TextBoxFor(x =&gt; x.Middlename, new { @class = "input-block-level" })
          @Html.LabelFor(x =&gt; x.StatusMaritalID)
          @Html.DropDownListFor(x =&gt; x.StatusMaritalID, Model.StatusMaritals, "-- Please Select --", new { @class = "input-block-level" })
      &lt;/div&gt;
      &lt;div class="span3"&gt;
          @Html.LabelFor(x =&gt; x.Surname)
          @Html.TextBoxFor(x =&gt; x.Surname, new { @class = "input-block-level" })
          @Html.LabelFor(x =&gt; x.NINumber)
          @Html.TextBoxFor(x =&gt; x.NINumber, new { @class = "input-block-level" })
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h3&gt;Contact Details&lt;/h3&gt;
  
  &lt;div class="row-fluid"&gt;
      &lt;div class="span3"&gt;
          @Html.LabelFor(x =&gt; x.PhoneNumber)
          @Html.TextBoxFor(x =&gt; x.PhoneNumber, new { @class = "input-block-level" })
      &lt;/div&gt;
      &lt;div class="span3"&gt;
          @Html.LabelFor(x =&gt; x.MobileNumber)
          @Html.TextBoxFor(x =&gt; x.MobileNumber, new { @class = "input-block-level" })
      &lt;/div&gt;
      &lt;div class="span6"&gt;
          @Html.LabelFor(x =&gt; x.Email)
          @Html.TextBoxFor(x =&gt; x.Email, new { @class = "input-block-level", type="email" })
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row-fluid"&gt;
      &lt;div class="checkbox span12" style="padding-left:0;"&gt;
          @Html.CheckBox("IsKnownByOtherNames", Model.IsKnownByOtherNames != null &amp;&amp; (bool)Model.IsKnownByOtherNames)
          @Html.LabelFor(x =&gt; x.IsKnownByOtherNames)
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And finally here is my entire save script</p>
  
  <pre><code>$("body").on("click", ".next", function(e){
              debugger;
              e.preventDefault();
              var btn = $(this);
              var form = btn.closest("form");
              form.validate({
                  rules: {
                      required: false
                  }
              });
              //check if form is valid
              if (form.valid()) {
                  var out = form.validate({
                      rules: {
                          required: true
                      }
                  });
                  if (form.valid()) { 
                      // disable the button to prevent multiple posts
                      btn.prop("disabled", true);
                      // serialise the form fields into an array
                      var fields = form.serializeArray();
                      // create a blank object to stuff the parameters into for the ajax call
                      var params = {};
                      // loop over the array and create a property for each item in array
                      // in the format expected by the controller action
                      $.each(fields, function (index, element) {
                          params[element.name] = element.value;
                      });
                      //loop over all checkboxes and see if they are checked or not
                      var checkboxes = form.find("input:checkbox")
                      $.each(checkboxes, function (index, element) {
                          params[element.name] = $(element).is(":checked");
                      });
                      // Make the ajax post call
                      // passing the parameters
                      $.post("UpdateCheck", params)
                      .success(function (data) {
                          alert("valid and complete");
                          // if fail alert the user of fail with error
                          if (data == false) {
                              //Create a toast message alerting of fail with reason
                              showSysMessage("Failed to Save. (Data Error)", { color: "#FFB347" });
                              // re-enables button
                              btn.prop("disabled", false);
                          } else {
                              btn.prop("disabled", false);
                              var currentpage = parseInt($(".TinyDancer").attr("data-currentpage"))
                              var newpage = currentpage + 1;
                              $.post("Page"+PageNos[newpage], {id:@Model.ID }).success(function(html){
                                  $("#WizardStage").val(PageNos[newpage]);
                                  $(".page[data-pageno='" + PageNos[newpage] + "']").parent().addClass("active").siblings().removeClass("active");
                                  $(".TinyDancer").slideUp(function(){$(".TinyDancer").html(html).promise().done(function() {$(".TinyDancer").slideDown();});});
                                  $(".TinyDancer").attr("data-currentpage", newpage);
                                  $("form").removeData("validator");
                                  $("form").removeData("unobtrusiveValidation");
                                  $.validator.unobtrusive.parse("form");
                              });
                          }
                      }).fail(function () {
                          showSysMessage("Failed to Save. (Network Transport Error))", { color: "#FFB347" });
                      });
                  } else {
                      alert("valid but not complete");}
              }else{
                  showSysMessage("Invalid Data. Please Check the Data in the Highlighted Fields", { color: "#FFB347" });
              };
          });
  </code></pre>