user1543784
user1543784

Reputation: 363

How to apply different conditions for multiple min value validation in jQuery Validation Plugin?

I want to validate a field using jQuery Validation Plugin. I want the field to have a minimum value, depending on some other conditions. If the conditions are satisfied, I want the minimum value required to be 3, otherwise I want it to be 4. How do I achieve it?

The logic is something like this -

education: {
    min: {
        param: 3,
        depends: function(element) {
            return ( /*conditions*/ );
        },
        param: 4,
        depends: function() {
            return ( /*otherwise*/ );
        },
    },
},

Upvotes: 0

Views: 168

Answers (1)

thedevlpr
thedevlpr

Reputation: 1101

Try just setting a handler to check for the condition you want and set the min value accordingly to the element

if(condition){
  $('#education').rules("add",{min:3});
}
else {
  $('#education').rules("add",{min:4});
}

As an example check out the jsfiddle http://jsfiddle.net/5RrGa/1487/

Upvotes: 1

Related Questions