Please help me solve the problem.
For form validation, I use jquery + jqueryvalidate + additianal-methods. The form is validated and even sent. The problem is that before submitting, the submitHandler method is executed about 600 times, which sometimes leads to cancellation of submission in browsers such as IE.
For debugging purposes, I put console.log() on submitHandler:
submitHandler: function(){ console.log('submitHandler!'); $( "#brief_form_new_test" ).submit(); } It can be seen that it is displayed several hundred times in the console.
Here is the jsfiddle .
I wish that submitHandler was executed only once, as it should be.
validation: $.validator.setDefaults({ invalidHandler: function(){ var fileInput = document.getElementById("fileUploadField"); if($('#brief_form_new_test .file-add input.error').length >= 1){ $('.file-add').css({ 'background': 'url("../img/attache.png") 0 -88px' }); }else{ $('.file-add').css({ 'background': 'url("../img/attache.png") 0 0' }); }; //console.log("not submitted!"); }, submitHandler: function(){ console.log('submitHandler!'); $( "#brief_form_new_test" ).submit(); } }); $.validator.addMethod("checkFileSize",function(value, element) { // check filesize var fileInput = document.getElementById("fileUploadField"), fileSize; if(fileInput.files[0]){ if(fileInput.files[0].size > 134217728){ return false; }else{ return true; } }else{ $('.file-add label.error').empty(); return true } }, "Размер файла превышен"); $().ready(function(){ $("#brief_form_new_test").validate({ rules: { attachment: { required: false, checkFileSize: true, extension: "doc,docx,txt,pdf,jpg,jpeg,png" }, message_new: { required: true, minlength: 10 }, name_new: "required", email_new: { required: true, email: true }, phone_new: { "required": true, "pattern": /[-0-9 -()+]+$/ } }, messages: { attachment: { required: 'File required', checkFileSize: 'Размер файла превышен', extension: "Неверный формат файла", }, message_new: { required: "Коротко опишите проект", minlength: "Введите не менее 10 символов" }, name_new: "Введите ФИО", email_new: "Введите корректный адрес", phone_new: { required: "Введите телефон", pattern: "Введите корректный телефон" } } }); });