Hi,

I have the following problem. My form is built dynamically on the
server side with the use of components. What I would like do is to
give components the ability to specify validation rules for the fields
they render and service. So if eg. component renders description field
it should be able to provide a JS snippet which sets the validation
rules for it.
To keep components independent, I'm unable to use single $
("#formId").validate(...) invocation to set up my form validation. I
do not want use metadata approach for that.

Is there a way I could add new validation rules to the form validator?
eg. by invoking validate() more than once with new rules to add? Or is
there some addRule() method which will allow me to do that? Btw. is
there a way to get hold of the validator/validation data assigned to
the form, so I could play with this data on my own eventually?

Sample usage might be:

In: name.html
$(document).ready(function() {
        $("#formId").validate({
         event: "keyup",
         rules: {
                "name": "required",
            },
         messages: {
                "name": {
                    required: "Name is required."
                },
            }
        });
});


In: description.html
$(document).ready(function() {
    $("#formId").validator().addRule({
     rules: {
            "desc": {
                required: true,
                maxLength: 100,
            }
        },
     messages: {
            "desc": {
                required: "Description is required.",
                maxLength: "Please enter a description no longer then
100 characters long."
            }
        }
    });
});


Thanks in advance for your help,
Cheers,
Bernard

Reply via email to