customize Validator.js when leaving the field

Asked

Viewed 36 times

0

Good afternoon, you guys

I am working with Validator.js (bootstrap library) to validate fields of a form, I have a custom email field:

$('#userForm').validator({
    custom: {
        validemail: function($el) {
            if(!valida_email($el.val())) {
                return "Email inválido"
            } 
        }
    }
});

This works perfectly, however I need to do another validation and if it returns true make the marking in the fomulário, but this only when the field loses focus, and I’m having a little difficulty before this situation.

One of the attempts I made but unsuccessfully was the following:

 $("#emailUser").blur(function() {
    $("#userForm").validator({
        custom: {
            validemail: function ($el) {
                if (getExistUserCpf($el.val())) {
                    return "CPF já cadastrado";
                }
            }
        }
    });
});

Here is the html

<div class="form-group col-sm-12 col-lg-6">
    <label>Endereço de E-mail</label>
    <input name="emailUser" id="emailUser" type="text" class="form-control email" placeholder="[email protected]" data-validemail required>
    <div class="help-block with-errors"></div>
</div>

I hope I’ve made my doubt clear.

  • I don’t understand Everton, the fields already validate or not at the event blur pq wants to implement another Blur?

  • What I implemented in Blur does not work, I want that when the user leaves the email field, the same validates if the email entered already exists in the database, if there is an email field should be marked with the message 'Email already exists' and do not let save the form, all this with Validator.js

No answers

Browser other questions tagged

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