jquery validation with identical form names create single error messages -


i have form set of form fields can added , removed dynamically (using javascript) , therefore use array values names (example: id="namesupplier[]") pass them via ajax.

my issue relates using jquery validate() - similar described in jquery validation identical form names. used solution suggested jab (second solution) on page, not work completely; when entering wrong value in example form field of second (third, etc) set, error message pops @ form field in first set (the error box related form field in second (third) set indicate error color expected, without message)

any idea how solve this?

code adding & removing form fields (getproductconfigform() returns string formfields of 1 set; each form field name=anarrayvalue[]))

 <script src="js/jquery-1.10.1.min.js"></script>  <script src="js/productconfigform1.js"></script>  <script>         //!max of 5 energy electricity products!         //values of these variables posted server (in $_post paremters)          var form = getproductconfigform(); //create  string product forms          var number_of_forms = 8;          //script adding , removing productss         $(document).ready (function () {             $('.btnadd').click (function () {                      $('.buttons').append(form); // end append                 $('div .btnremove').last().click (function () {                      $(this).parent().last().remove();                     }); // end click             }); // end click                          }); // end ready  </script> 

code jquery validate() function:

<script> $(function() {      $("#myform").validate({      rules: {             // simple rule, converted {required:true}               "productname[]": {                 required:true,                 minlength: 2,                 maxlength: 30,             },               "energyunitinv[]": {                 required:true,                 number: true,                 maxlength: 8,             }               } //rules     }); //validate()  }); //function  </script> 

code of mentioned javascript function getproductconfigform() returns string formfields:

function getproductconfigform() {  var form;   form = '<div>\<p> product - algemeen </p>\         <label class="field2" for="productname[]"> product naam </label> <input     id="productname[]" type="text" name="productname[]"> <br>\         <label class="field2" for="eproducttype[]"> product type</label> <select name="eproducttype[]"> \   <input type="button" class="btnremove" value="remove"><br></div>';   return form; } 

i have few suggestions:

you adding validation same form time:

$("#myform").validate(...)

add class every form can this: $(".myformclass").validate(...)

you should not add forms same id (myform) page, result in invalid html. don't have add ids forms example, or add number end of id, myform1, myform2, ... id.

i don't think array "productname[]", name square brackets in it, makes no difference whatsoever.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -