Skip to content

Instantly share code, notes, and snippets.

@AstakhovArtem
Created July 25, 2014 11:49
Show Gist options
  • Save AstakhovArtem/b8a65fe15c76e38c2b11 to your computer and use it in GitHub Desktop.
Save AstakhovArtem/b8a65fe15c76e38c2b11 to your computer and use it in GitHub Desktop.
Validation.add(
'validate_unique_email',
'This email is already in use! Please log in in order to proceed',
function(value){
var url = validationUniqueEmail + '?email=' + encodeURIComponent(value);
var ok = false;
new Ajax.Request(url, {
method: 'get',
asynchronous: false,
onSuccess: function(transport) {
var obj = response = eval('(' + transport.responseText + ')');
validateTrueEmailMsg = obj.status_desc;
if (obj.ok === false) {
Validation.get('validate-email').error = validateTrueEmailMsg;
ok = false;
} else {
ok = true; /* return true or false */
}
},
onComplete: function() {
if ($('advice-validate-email-email')) {
$('advice-validate-email-email').remove();
}
if ($('advice-validate-email-email_address')) {
$('advice-validate-email-email_address').remove();
}
if ($('advice-validate-email-billing:email')) {
$('advice-validate-email-billing:email').remove();
}
if ($('advice-validate-email-shipping:email')) {
$('advice-validate-email-shipping:email').remove();
}
if ($('advice-validate-email-_accountemail')) {
$('advice-validate-email-_accountemail').remove();
}
}
});
return ok;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment