It is has been suggested that it is best to initialize a $('#form').validate({}) function on page load rather than on a click event: jquery.form/validate plugin only allow submit if input is changed
I'm wondering how to do this for multiple dynamically added forms without wrapping the $('#form').validate({}) function inside of a on('click', 'input[type="submit"]', function.
Take this code for example:
var id="some identifier for the specific form that is submitted";
`$('#form'+id).validate({})`
- How does this unique identifier,
id, which is required to distinguish each form get created in the first place? - And what if you don't know the
idafter the page is loaded because it has been created dynamically, e.g., by AJAX.
I have been doing this but this is is what's not recommended:
$(document.body).on('click', 'input[type="submit"]', function(){
var id=this.id;
$('#form'+id).validate({});
});
thoughts?
thanks, tim
comment_idfor the next form until I insert the comment into the database and return its rowid. I guess you are right though I could initializevalidate()on the new form after mytemplating()function generates it.validate()onsubmit, I'd initialize it immediately after the form is created ($(#myNewform).validate({ options, etc. }))$('form').each(function(){...$(this).validate()});?validate()options/instances are the same for all the existing forms, I don't see why you couldn't initialize them all with an.each(function(){.