Leto
Leto

Reputation: 2674

jquery validate plugin Using dependency and set arguments

My question is quite simple :

How to set dependency on a field and set params to the rule function ? What's the key to set params in ?

$('#form').validate({
    rules: {
        somefield: {
            minlength: {
                depends: function() {
                    return $('#checkbox').prop('checked');
                }, 
                keyToSetParams??: 5
            }
        }
    }
});

Without dependency, it would look like this :

$('#form').validate({
    rules: {
        somefield: {
            minlength: 5
        }
    }
});

Upvotes: 2

Views: 306

Answers (1)

Leto
Leto

Reputation: 2674

I found the solution after some debugging, the key name is "param" so it look like:

$('#form').validate({
    rules: {
        somefield: {
            minlength: {
                depends: function() {
                    return $('#checkbox').prop('checked');
                }, 
               param: 5
            }
        }
    }
});

Upvotes: 2

Related Questions