views:

544

answers:

1

How to validate a bunch of fields that are not enclosed by FORM tag using jquery validate?

+1  A: 

You won't be able to get the same effects with jquery validate if you don't have a form tag.

You could attempt something like the following


function testValidationNoForm() {
    var nameValue = jQuery("#cname");
    var isValid = $("<form action='' name=''><input name='name' class='required' minlength='2' value='" + nameValue.val() + "'/></form>").valid();
    alert('isValid = ' + isValid);
}

So here you're building the form on the fly and getting the valid message.

Shaun F
Thanks for your reply. Don't we have any straight method for it?
Niger
No because the validate plugin relies on FORM elements. You need to work around this by creating a FORM element on the fly in jQuery and validating your dynamic element that you create.
Shaun F