I'm using the next Jquery Validator script;
jQuery.validator.addMethod("letras", function (value, element) {
return this.optional(element) || value == value.match(/^[a-zA-Z ñÑáéíóúüç]+$/);
}, "Only letters.");
$(document).ready(function () {
$('#inscripcion').validate({
errorClass: 'form-control-error',
validClass: 'form-control-sucess',
ignore: "",
submitHandler: function (form) {
if ($("#inscripcion").validate() == true) {
alert("Form not completed");
} else {
form.submit();
}
},
rules: {
nombrer: {
minlength: 2,
letras: true,
required: true
},
apellidor: {
minlength: 2,
required: true
},
cedular: {
minlength: 7,
number: true,
required: true
},
highlight: function (element) {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
},
success: function (element) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
}
});
}); // end document.ready
$('#menu a[href="#estudiante"]').click(function (event) {
var estado = $('#inscripcion').valid();
if (estado == false) {
alert("You miss some data please complete it");
}
});
$('#botonestu').click(function (event) {
var estado = $('#inscripcion').valid();
if (estado == false) {
alert("You miss some data please complete it");
}
});
The problem is that if I use 'ignore: "",' the events that I made for when someone clicks a tab or a button activates even if the especified tab is full. But if i removeit somebody could click the submit button directly and it would submit the entire form even if it's complety empty. And also the "alert" in submitHandler its not working even tho the form.submit() is.