I have to validate a form like this:
$('#formfile').validate({
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
ignore: '',
//focusInvalid: true,
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
element.focus();
},
rules: {
if(country == "INDONESIA") {
tax: {
required: true
}
}
},
messages: {
if(country == "INDONESIA") {
tax: "Please insert file Tax"
}
}
});
Can I do that? I want to check if Country is Indonesia or not, and if Country is Indonesia that field must be mandatory. Otherwise, if Country is not Indonesia, that field can be ignored. Any suggestion?
Edit: I forgot I used variable to get Country - var Country = $('#country').val();