customize validator.js when leaving the field

0

Good afternoon guys

I'm working with validator.js (bootstrap library) to validate fields in 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, but I need to do another validation and if it returns true to do the marking in the form, but this only when the field loses focus, and I'm having a little difficulty in this situation. >

One of the attempts I made but without success was as follows:

 $("#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 my question has been clear.

    
asked by anonymous 11.08.2018 / 21:34

0 answers