Question

Below is the html i use

    <div id="my_page">
<div>
    <input type="text" id="destination_name" name="destination_name" value="Paris, France"/>
</div> 
<div>   
<input type="hidden" id="destination_code" name="destination_code" value=""/>
</div>
    </div>

Below is the validation rules

$('#my_page').validate({

    rules:{
         destination_name:{ required:true }
        }
});

How to activate error in 'destination_name' if 'destination_code' value is null

Was it helpful?

Solution

Try writing a function that returns false if destination_code is false. Sample code that I found in the documentation section.

$(".selector").validate({
  rules: {
    contact: {
      required: true,
      email: {
        depends: function(element) {
          return $("#contactform_email:checked")
        }
      }
    }
  }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top