0

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');
shaile
  • 896
  • 7
  • 10
  • 3
    `async: false` has been deprecated please don't use it. Instead specify a callback which checks the response. – Script47 Aug 18 '17 at 08:31
  • Simple use `Remote method` for checking duplicate -https://jqueryvalidation.org/remote-method/ – JYoThI Aug 18 '17 at 08:43

0 Answers0