开发者

jquery validation rules - conditional?

开发者 https://www.devze.com 2023-03-27 19:24 出处:网络
In my jquery validation, is it possible to apply a certain rule only, for example, when the $_GET[\'name\']); is Billybob?

In my jquery validation, is it possible to apply a certain rule only, for example, when the $_GET['name']); is Billybob?

here is a snippet of my rules:

    $("#form").validate({
        debug: false,
        rules: {
        semester: "required",
        courseno:
        {required: true,
        courseno: true},
        coursename: "required",
        "professor[]": "required",
        },

开发者_运维知识库for example, coursename is only required when Billybob is present.

Is that even possible?


Can't you do:

var options = {
    debug: false,
    rules: {
    semester: "required",
    courseno:
    {required: true,
    courseno: true},
    "professor[]": "required"
};
var coursename = <?php echo $name == 'BillyBob' ? 1 :  0; ?>;
if(coursename) {
    options.coursename = 'required';
}
$("#form").validate(options);
0

精彩评论

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