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

validation_error bug in the demo example

Open viktorix opened this issue 8 years ago • 3 comments

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.

viktorix avatar Sep 06 '16 20:09 viktorix

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 :)

jeffreykemp avatar Sep 07 '16 00:09 jeffreykemp

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

viktorix avatar Sep 08 '16 03:09 viktorix

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

jeffreykemp avatar Sep 08 '16 04:09 jeffreykemp