Jquery validate with type button

0

Hello, I have a form that uses direct javascript to send the data, and its type is button.

<button type="button" id="login_submit_patient" class="btn btn-focus m-btn m-btn--pill m-btn--custom m-btn--air uppercase">

But I can not use jquery validate without for type submit.

      $(document).ready(function(){
      $("#login-form-patient").validate({
        rules: {
           ........
        }
  });

Does anyone know how to do it? Thank you

    
asked by anonymous 22.11.2018 / 17:19

1 answer

2

You can use .valid () which returns true or false depending on whether your form is valid or not.

$("#login_submit_patient").on("click",function(){
  if(!$("form").valid())
    console.log("Formulário inválido");
});

$("form").validate({
    messages: {
        name: "Nome obrigatório",
        email: {
            required: "E-mail obrigatório"
        }
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>

<form>
    <div>
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" required>
    </div>
    <div>
        <label for="email">Email:</label>
        <input type="email" name="email" id="email" required>
    </div>
    <div>
        <button type="button" id="login_submit_patient">Enviar</button>
    </div>
</form>
    
22.11.2018 / 17:34