Still is not clear to me how I can validate a dynamic form fields using jQuery validate ()
Suppose I have a form like the following:
<form id="myform" action="" ...>
<input type="text" form-control" name="cauthor[]" id="cauthor1" value=""/>
....
<button type="button" class="clone btn btn-primary" value="Add">
....
<button type="submit" name="submit" value="submit">
...
</form>
As you can see I have a dynamic field (cauthor[]); So user can hit the Add button to create a new input field. Then after hitting the Add button my form will look like this:
<input type="text" form-control" name="cauthor[]" id="cauthor1" value=""/>
<input type="text" form-control" name="cauthor[]" id="cauthor1" value=""/>
<input type="text" form-control" name="cauthor[]" id="cauthor1" value=""/>
Now the question is? How to validate all the fields?
$("#casos_clinicos_form").validate({
rules: {
'cauthor[]': {
required: true
}
},
messages: {
'cauthor[]': "Author name not informed! Please correct and try again."
}
});
It only validates the first one.
If you know how to handle the above, please reply.