Im making custom formular and for one field I need a username ajax validation.
I prepared a custom handler in jQuery:
document.formvalidator.setHandler('usernamecheck', function(value) {
jQuery(".username_message").html('');
jQuery(".username_message").hide();
jQuery.ajax({
url:'index.php?option=com_xxx&task=user.checkUserName',
type: "POST",
data: {
'username': value
}
}).done(function(msg) {
console.log(msg);
msg = JSON.parse(msg);
if (msg.msg==='false')
{
jQuery(".username_message").show();
jQuery(".username_message").html(msg.html);
return false;
}
else
{
return true;
}
})
});
Ajax works fine but while form validation this handler always add invalid class to my field.
Even if all method returns true, after validation I have red bordered input. But when I remove ajax calling from this method and for testing check only by if-else, it works ok.
Anyone knows why? Maybe it can't be done by ajax in handlers?