Jquery validate works after Sweet Alert

0

Well, all the input of the form I put "required" and they work perfect. Now I put the sweet alert of the form's sending confirmation and it does not check that they are completed .. It sends them empty, even if they say "required" ..

jQuery('#btn-submit').click(function(event){

 // Wait for the DOM to be ready
$(function() {
  // Initialize form validation on the registration form.
  // It has the name attribute "registration"
  $("form[name='uploadForm']").validate({
    // Specify validation rules
    rules: {
      // The key name on the left side is the name attribute
      // of an input field. Validation rules are defined
      // on the right side
      name: "required",     
    },
    // Specify validation error messages
    messages: {
     name: "Please enter your firstname",     
    },
    // Make sure the form is submitted to the destination defined
    // in the "action" attribute of the form when valid
    submitHandler: function(form) {
      form.submit();
    }
  });


    event.preventDefault();
    swal({
        title: "Desea registrarse en Wouu como usuario?",
        text: "Para un mejor funcionamiento del sitio y un mejor trabajo debe completar todos los datos del formulario.",
        icon: "warning",
        buttons: {
            cancel: "Olvidé algo!",
            confirm: "Estoy seguro!",
        },
        dangerMode: true,
    })
    .then((willDelete) => {
        if (willDelete) {
            $('#uploadForm').submit();
            swal("Bienvenido a wouu", "Con tu nombre de usuario puedes ingresar!", "success");
        } else {
            return false;
        }
    });
});


   
});
<html>
<head>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script  src="https://code.jquery.com/jquery-3.3.1.js"  integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.15.1/jquery.validate.min.js"></script>

</head>
<form id="uploadForm" name="uploadForm"  method="...">
<input type="text" name="name" id="name">
<button type="submit" id="btn-submit">Enviar</button>
</form>

</html>
    
asked by Juampi 25.10.2018 в 16:26
source

1 answer

0

You can stop the submit event of your form in the following way and execute the alert

$('#uploadForm').on('submit', function(e){
  e.preventDefault()
  if($(this).find('#name').val() === '')
    ejecutas un alert de sweetAlert

})

    
answered by 25.10.2018 в 17:53