title: Trigger validation on form with multiple sections and unknown input fields
body: <p>I'm trying to validate a complex form and by complex I mean that form is just one but it has been split in four sections and I made a simple wizard to show them. I'm using <a href="http://jqueryvalidation.org/" rel="nofollow">jQuery Validation</a> but it's not working as I want and also have some doubts about it. Based on <a href="http://jquery.bassistance.de/validate/demo/" rel="nofollow">this example</a> (second form) I made my code as follow:</p>
  
  <pre><code>$("#product_create").validate({
      rules: {
          product_name: {
              required: true,
              minlength: 10,
              maxlength: 50
          },
          product_price: {
              required: true,
              number: true,
              minlength: 2
          },
          product_quantity: {
              required: true,
              digits: true,
              minlength: 1
          }
      },
      messages: {
          product_name: {
              required: "El nombre del producto no se puede dejar vacío",
              minlength: "El nombre del producto no puede tener menos de 10 carácteres",
              maxlength: "El nombre del producto no puede tener más de 50 carácteres"
          },
          product_price: {
              required: "Debes introducir un precio",
              number: "El precio debe ser un número decimal o no"
          },
          product_quantity: {
              required: "Debes introducir una cantidad",
              number: "La cantidad debe ser un número"
          }
      }
  });
  </code></pre>
  
  <p>If I understand good then on <code>keyup</code> event fields should validate and they are not since errors doesn't come up. So first problem regarding this is: why it doesn't validate? What's wrong in my solution? Second one is how I validate <code>product_price</code> and <code>product_quantity</code> only if they are visible?</p>
  
  <p>Now regarding this same topic I have another doubt, I create several fields on the fly and yes I know theirs ID each time, in this case how I apply rules to those fields?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I figure out where the problem with <code>keyup</code> was, validation is made by input name and not input id's as I tough, so this part is done. </p>
  
  <p>The second problem still pending. For example I can generate three fields with name <code>variation[pprice][]</code> and the fly but can be five or more or whatever, how I add those fields to rules and validation part? Can I just add the rule for <code>variation[pprice][]</code> and it will validates no matter how many elements with the same name are in the form? </p>
  
  <p>Also is pending the part of validate fields just if they are visible</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Since <code>variation[pprice][]</code> is a array of items, can I use <code>$.each</code> to move for them and assign rules? </p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>Following recommendations by @Sparky I change my code to this:</p>
  
  <pre><code>$('#variations_holder input.pprice').each(function() {
      $(this).rules('add', {
          required: true,
          number: true,
          messages: {
              required: "Debes introducir un precio de la variación",
              number: "El precio de la variación debe ser un valor numérico o decimal"
          }
      });
  });
  </code></pre>
  
  <p>But in Firebug I get this error:</p>
  
  <blockquote>
    <p>TypeError: e.validator.methods[o] is undefined</p>
  </blockquote>
  
  <p>Which prevent code execution for the script, what I miss in this case? </p>
  
  <p><strong>UPDATE 4</strong></p>
  
  <p>Supposing that I can't use several forms so I only have one form with many sections (using <code>section</code> tag) and I handle to move between each. I'm trying to call <code>validate()</code> in same form but two times and validation at <code>step5</code> didn't work since fields pass. This is the code I'm using for that:</p>
  
  <p>function validateWizard(step) {
      var is_valid = true;</p>
  
  <pre><code>switch (step) {
      case 1:
          if ($("#selected_category").val() === '' || $("#selected_category").val().length === 0) {
              alert("Debes seleccionar una categoría antes de continuar");
              is_valid = false;
          }
          break;
      case 2:
          $("#product_create").validate({
              rules: {
                  "product[name]": {
                      required: true,
                      minlength: 10,
                      maxlength: 50
                  },
                  "product[price]": {
                      required: true,
                      number: true,
                      minlength: 2
                  },
                  "product[quantity]": {
                      required: true,
                      digits: true,
                      minlength: 1
                  },
                  "product[description]": {
                      required: true
                  }
              },
              messages: {
                  "product[name]": {
                      required: "El nombre del producto no se puede dejar vacío",
                      minlength: "El nombre del producto no puede tener menos de 10 carácteres",
                      maxlength: "El nombre del producto no puede tener más de 50 carácteres"
                  },
                  "product[price]": {
                      required: "Debes introducir un precio",
                      number: "El precio debe ser un valor numérico o decimal"
                  },
                  "product[quantity]": {
                      required: "Debes introducir una cantidad",
                      number: "La cantidad debe ser un número"
                  },
                  "product[description]": {
                      required: "Debes introducir una descripción del producto"
                  }
              }
          });
  
          is_valid = $("#product_create").valid();
  
          if (is_valid) {
              $('#variations_holder input.pprice').each(function() {
                  pprice = $.trim(this.value);
                  if (!pprice.length) {
                      $(this).focus();
                      $(this).addClass('error');
                      is_valid = false;
                  } else if (!/^[1-9]\d*(\.\d+)?$/.test(pprice)) {
                      $(this).addClass('error');
                      is_valid = false;
                  }
              });
  
              // Validate quantity in variation
              $('#variations_holder input.pqty').each(function() {
                  pqty = $.trim(this.value);
                  if (!pqty.length) {
                      $(this).focus();
                      $(this).addClass('error');
                      is_valid = false;
                  } else if (!/^[1-9]\d*$/.test(pqty)) {
                      $(this).addClass('error');
                      is_valid = false;
                  }
              });
          }
          break;
      case 3:
          break;
      case 5:
          $("#product_create").validate({
              rules: {
                  "stock[sku]": {
                      required: true,
                      minlength: 10,
                      maxlength: 20
                  },
                  "stock[width]": {
                      required: true,
                      number: true,
                      minlength: 1
                  },
                  "stock[height]": {
                      required: true,
                      number: true,
                      minlength: 1
                  },
                  "stock[length]": {
                      required: true
                  },
                  "stock[weight]": {
                      required: true,
                      number: true,
                      minlength: 1
                  },
                  "stock[description]": {
                      required: true
                  },
                  "warranty[description]": {
                      required: true
                  },
                  "warranty[valid_time]": {
                      required: true,
                      digits: true
                  }
              },
              messages: {
                  "stock[sku]": {
                      required: "El SKU no se puede dejar vacío",
                      minlength: "El SKU no puede tener menos de 10 carácteres",
                      maxlength: "El SKU no puede tener más de 50 carácteres"
                  },
                  "stock[width]": {
                      required: "Debes introducir un ancho",
                      number: "El ancho debe ser un número"
                  },
                  "stock[height]": {
                      required: "Debes introducir una altura",
                      number: "La altura debe ser un número"
                  },
                  "stock[length]": {
                      required: "Debes introducir una longitud",
                      number: "La longitud debe ser un número"
                  },
                  "stock[weight]": {
                      required: "Debes introducir un peso",
                      number: "El peso debe ser un número"
                  },
                  "stock[description]": {
                      required: "Debes introducir una descripción del stock del producto"
                  },
                  "warranty[description]": {
                      required: "Debes introducir una descripción de la garantía para este producto"
                  },
                  "warranty[valid_time]": {
                      required: "Debes introducir un período de validez",
                      digits: "El período de validez no es válido"
                  },
              }
          });
  
          is_valid = $("#product_create").valid();
          break;
  }
  
  return is_valid;
  </code></pre>
  
  <p>}</p>
  
  <p>my question is why if form is not valid at <code>step5</code> it pass? Should't fail?</p>