开发者

Validate set of fields separately from rest of form

I am using the jQuery Validate plugin.

I have a series of jQuery-ui tabs containing many input fields, and a single spans the entire set of fields. In one of these tabs there is a set of text fields that I want to validate separately from the main form. That is, when my main form submits, Validate should not check those fields. The problem is that those special fields exist (in HTML) inside of the original that is already being validated.

It would be great if I could use a nested around those extra fields, tired to a separate Validate process, but this is obviously not legal.

The initial form Validation is done with a simple $("#myform").validate(). Is there way to apply a validate() to a set of fields without calling it against a form? Somethin开发者_StackOverflowg like: $("#mydiv").validate(), and since there would be no submit handler (it's a div, not a form), I would handle the "validate" initiation manually when a Button is pressed.

This way, when the main form (containing this div) is submitted, my existing validation logic runs, however if they fill out that special set of fields and press the button, I can validate only those fields separately from the rest of the form.


The initial call to $(formselector).validate(options) (the one which sets up event handlers for submit, focus, keyup, blur and click) returns a Validator object:

var validator = $("#myform").validate(options);

You can use this Validator object to perform validation of single element with Validator.element(elementSelector) method:

var isValid = validator.element('#myelement');

This method returns true if element is valid, false otherwise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜