开发者

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

开发者 https://www.devze.com 2023-02-04 07:16 出处:网络
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.

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:

$(开发者_如何学JAVAdocument.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?


yes, it's perfectly fine... and one thing,

$('#new_listing_form').validate({

is same thing as yours... # means it's a document.getElementById().

0

精彩评论

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