I am using a jquery validation customized function to check duplicate values in database with ajax call and the ajax call is async. The issue is that when I fills any value and click on submit button directly "without focus out from the field" the form is not getting submit though the validation function is returning true. I need to click on submit again to submit the form. Below is some code I am using: Add customized rule:
jQuery.validator.addClassRules("checkDuplicate", {checkDuplicate: true});
The function "checkDuplicate" :
$.validator.addMethod("checkDuplicate", function (value, element) {
var returnValue = false;
$.ajax({
type: "POST",
async: false,
url: '/check-duplicate',
data: {value: $('#value').val()},
success: function (response)
{
if (response.status == true) {
returnValue = false;
} else {
returnValue = true;
}
}
});
return returnValue;
}, 'Duplicate value');