Jquery Validate does not run the event when fields are autocompleted

1

I'm trying to validate a form without submitting it. What I've done so far works well. The problem is when the autocomplete browser completes the login and password that have been saved to the IP. If I delete the auto-completed field and give focusOut the event to validate form is not triggered.

I'm using the following:
jquery -validation - 1.15.0
google-chrome version 49.0.2623.87 (64-bit)

Steps:
1 - Create a form and submit this form. 2 - Make browser save this information as the default values for that site.
3 - Go back to the form and delete an "automatically filled" field and try to trigger some event for jquey-validate to validate.

It should validate the field without the need to submit. In my case you are not triggering the event and validation is not occurring.

form

<form name="form" id="loginform" class="lm-login-form" method="post" action="./?_task=login">
  <div id="userid" class="lm-login-item">
    <div class="lm-login-label">
      <label for="rcmloginuser"><roundcube:label name="mail" /></label>
    </div>
    <div class="lm-login-field">
      <input name="_user" id="rcmloginuser">
    </div>
  </div>

  <div id="pwdid" class="lm-login-item">
    <div class="lm-login-label">
      <label for="rcmloginpwd"><roundcube:label name="password" /></label>
    </div>
    <div class="lm-login-field">
      <input name="_pass" id="rcmloginpwd" type="password">
      <a href="#" id="showpass">Exibir</a>
    </div>
  </div>

  <p class="formbuttons">
    <input type="submit" id="submitloginform" class="lm-login-submit" value="Entrar">
  </p>
</form>

Validation script

$(document).ready(function() {
  $( '#loginform' ).validate({
    rules: {
      _user: {
        required: true,
        email: true
      },
      _pass: {
        required: true
      }
    },
  });
});
    
asked by anonymous 07.04.2016 / 22:15

1 answer

0

When the browser completes the fields automatically, the event that triggers the validate is not called. You need to call it manually, so try:

$(document).ready(function(){
 checkInput = setInterval(function(){
  var autoCompleted = false;
  $("#loginform input").each(function(input){
    input = $("#loginform input").eq(input);
    if($(input).val()){
      $(input).val($(input).val());
      $(input).change();
      autoCompleted = true;
    }
    if(autoCompleted){
      clearInterval(checkInput);
    }
  })
 }, 10);
$("#loginform input").focus(function(){
 $(this).change();
 $(this).val($(this).val());
});
$( '#loginform' ).validate({
  rules: {
   _user: {
     required: true,
     email: true
   },
   _pass: {
     required: true
   }
  },
 });
})
    
08.04.2016 / 00:02