Is it possible to supply the jQuery Validation plugin with a rules object?

Posted by ethagnawl on Stack Overflow See other posts from Stack Overflow or by ethagnawl
Published on 2011-01-12T09:45:22Z Indexed on 2011/01/12 9:53 UTC
Read the original article Hit count: 180

Filed under:
|
|

I took the rules that I'd been using to validate my form and broke them out into a JSON object, hoping to use the same set of rules for client/server validation.

So, where I had:

$(document.getElementById('new_listing_form')).validate({
    rules: {
        apt: {
            required: true
        }
    }
});

I'm attempting to use:

var rules_obj = {
    apt: {
        required: true
    }
};
$(document.getElementById('new_listing_form')).validate({
    rules: rules_obj 
});

... and the form is not being validated.

Does anyone know if this is possible?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery