I am using jquery validation plugin and using this code, I try to fire some errors when fields do not meet required specifications
$(document).on('click', '#btn_save', function() {
$('form#new_inquiry').validate({
onkeyup: false,
errorClass: 'error',
validClass: 'valid',
highlight: function(element) {
$(element).closest('div').addClass("f_error");
},
unhighlight: function(element) {
$(element).closest('div').removeClass("f_error");
},
errorPlacement: function(error, element) {
$(element).closest('div').append(error);
},
rules: {
pname: { required: true },
pid: { required: true, min: 1 },
country: { required: true },
cid: { required: true, min: 1 },
city: { required: true },
delivery_date: {
require_from_group: [1, '.delivery']
},
delivery_text: {
require_from_group: [1, '.delivery']
},
address: { required: true },
content: { required: true }
},
messages: {
pname: "You must enter a customer name before saving",
country: "You must select a valid country",
city: "Please fill in the city",
address: "Please fill in the address",
content: "Please fill in the order content"
},
invalidHandler: function(form, validator) {
$.sticky("Inquiry cannot be saved for the moment. </br>Please corect errors marked up", {autoclose : 5000, position: "top-right", type: "st-error" });
},
submitHandler: function(form) {
$.ajax({
url: 'view/inquiry/inquiry_insert-exec.php',
type: 'post',
dataType: 'json',
data: $('form#new_inquiry').serialize(),
beforeSend: function() {
$('#amount').val($('#amount').val().toString().replace(/\,/g, '.'));
$('#btn_save').attr('disabled', true);
$('#btn_save').after('<span class="wait"> <img src="<?= DIR_MEDIA;?>img/ajax_loader.gif" alt="" /></span>');
},
complete: function() {
$('#btn_save').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
if (json['status']) {
if (json['id']) {
location = '?route=home/inquiry/insert&id='+json['id']+"&tab=#tab2";
//$('#myTab a[href="#tab2"]').tab('show');
} else {
location = '?route=home/inquiry';
}
} else {
$.sticky("There were errors while saving inquiry.</br>" + json['status'], {autoclose : 5000, position: "top-right", type: "st-error" });
}
}
});
}
});
if ($('#new_inquiry').valid()) {
}
});
But, this code is doing nothing.. I guess I am having a error somewhere but I do not understand where it could be I am using Firebug to track errors, but still no error fires after #btn_save is clicked The validate() is checked on the click of two buttons, and depending on the clicked one, the next event would be different, so the valid() function is used inside the click event, but still nothing happens. How can I see the errors, if any? I guess there are if the code does nothing