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

validation_error bug in the demo example #20

Open viktorix opened 8 years ago

viktorix commented 8 years ago

It looks like there's a bug with how error validation_error function works. https://github.com/mailgun/validator-demo/blob/master/index.html#L88

// if email is invalid
      function validation_error(error_message) {
        $('#status').html(error_message);
      }

$('#status').html(error_message); does not fire.

The "Address is invalid." check and error message does work properly, but it is fired inside validation_success function as the last remaining "else" condition.

You can easily test this by removing $('#status').html(error_message); and testing validator. You'll see it still works just fine. This is a problem because if we want to do something else when email is invalid, let's say addClass it does not work.

jeffreykemp commented 8 years ago

I think that is how it is supposed to work.

If the ajax call fails, you expect the validation error to run.

If the ajax call succeeds, you expect the validation success to run. The result of the validation might be that the email address appears to be invalid, but this is still a "success" as far as the validator is concerned.

Unless I'm mistaken :)

viktorix commented 8 years ago

Yea, that might be the case. If it is, maybe it's the comment that explains what the function does needs to be re-worded: if email is invalid

jeffreykemp commented 8 years ago

That's just the sample code - agreed the comment could be misleading