mailgun / validator-demo

Mailgun email address jquery validation plugin http://mailgun.github.io/validator-demo/
Apache License 2.0
257 stars 80 forks source link

No validation on first call #25

Open arcteixeira opened 6 years ago

arcteixeira commented 6 years ago

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?

macaetano commented 6 years ago

Same issue here, the first call does never work.

jcoon97 commented 6 years ago

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.