Jquery validate with type button

Asked

Viewed 251 times

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 cannot use jquery validate without type Submit.

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

Anyone know how to do it? Thank you

1 answer

2

You can use .Valid() returning 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>
<script src="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>

  • vlw friend, it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.