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
id
after 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