0

I have a jquery validation script as follows

$("#form").validate({
rules:{
    type:{
        required:true
         }
      }
});

i want the type field to be required only when update mode is true. How can i enhance this script to do that?

1 Answer 1

1

you could try:

$("#form").validate({
  rules:{
    type:{
        required:function(elem) {
           return +update_mode  > 0; //convert true/false to number and check
        }        
  }
});

In the code, variable update_mode can have either true or false value, and the code checks if update_mode is true, in which case it makes the field required for validation else not-required.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.