trigger function after form validation

2

I have a form with validation, and I need to insert after validating this form a waiting hourglass (as if you were loading the page).

I would like to know how to join these two functions, and after validating the form, it triggers the other:

//Validacao cadastro-completo.php
$("#form3").validate({
    rules: {
    constituicao: {
      required: true,
      minlength: 10,
      validadata: true
    },
    email: {
      required: true,
      email: true
    },
  messages: {
    constituicao: {
      required: "Esse campo é obrigatório",
      minlength: "Data Inválida"
    },
    email: {
      required:"Esse campo é obrigatório",
      email: "Email inválido"
    }
  }
});


function loading() {
    $('body').append("<div class='loading'></div>");        
}
$('.open-loading').click(function () {
    loading();
});
    
asked by anonymous 27.07.2017 / 20:39

2 answers

2

In the validate, I have an attribute named: submitHandler that you can put the method that will execute after the form validation, according to the code snippet below:

   function loading() {
        $('body').append("<div class='loading'></div>");        
   }

   $("#form3").validate({
        submitHandler: function(form) {
           loading();
        }
   });

The simplest and check in the plugin documentation: link

    
27.07.2017 / 21:16
0

There is a javascript plugin called jQuery Form . I recently posted a example of how to use it.

It has the parameter beforeSubmit that you can call a function and apply $("#form3").validate() and wait hourlight.

beforeSubmit:  valida

// pre-submit callback 
function valida(formData, jqForm, options) { 
    // Aplique as validações do form aqui  
    // O return false previne o submit do form
    // Qualquer retorno ao contrário de false permitirá o submit do form 
    return true; 
} 
    
27.07.2017 / 21:19