Generic selection using jquery validate -
as relative jquery novice please bear me if there simple solution problem. using jquery validate works beautifully when selecting unique id
eg.
$("#myform").validate({ debug: false, rules: { field1: "required" }, messages: { field1: "required" }, submithandler: function(form) { $.post('formaction.php', $("#myform").serialize(), function(data) { $('#results').html(data); }); } });
i need extend work generically number of automatically generated forms myform1, myform2
etc.
can validate via common class selector $("myform")
, apply submithander
specific form (myform1
, myform2
, etc.) eg:
$(".myform").validate({ debug: false, rules: { field1: "required" }, messages: { field2: "required" }, submithandler: function(form) { $.post('formaction.php', $(this).serialize(), function(data) { $('#results').html(data); }); } });
many thanks
try this
$('[id^=myform]').validate(); // work id pattern myform1, myform2... // selector target forms id start // myform
or
$('.myform').validate() // giving common class forms
autocomplete calling submithandler
this
validator.settings.submithandler.call( validator, validator.currentform );
which means this
refer validator object
not form
, use form
argument refer form , serialize it's fields this
$(form).serialize()
so, within submit handler instead of $(this).serialize()
use, $(form).serialize()
.
Comments
Post a Comment