validator-demo icon indicating copy to clipboard operation
validator-demo copied to clipboard

No validation on first call

Open arcteixeira opened this issue 6 years ago • 2 comments

Hi,

The first call I make to mailgun_validator doesn't really happen. I've checked the network log and there is no validation requests. I then focus on the element that calls the validation, blur and the call is correctly made.

This is my code:

$("#email").blur(validateEmail);

var validateEmail = function() {
    var email = $("#email");
    if (email.val() !== "") {
        email.mailgun_validator({
               api_key: 'XXXXXXX',
               in_progress: in_progress_callback, // called when request is made to validator
               success: success_callback,         // called when validator has returned
               error: validation_error,           // called when an error reaching the validator has occured
        });
};

I have logs in every method and I see that after the first call neither success_callback nor validation_error are called. Any ideas?

arcteixeira avatar Apr 10 '18 14:04 arcteixeira

Same issue here, the first call does never work.

macaetano avatar Apr 23 '18 17:04 macaetano

If you look at the code, it binds to an element object and then only runs the validator once the input is blurred. This was posing a problem for me, as well, so I created my own repository inspired by this one that will let you call the method whenever you like and receive a callback response via AJAX. You can view it here.

jcoon97 avatar Oct 30 '18 03:10 jcoon97