Jquery added class rule executes on page load

I am using jquery validate to validate a form and adding a class rule using

$(document).ready(function () { 
    jQuery.validator.addClassRules("checkDuplicate", {checkDuplicate: true});

The function checkDuplidate executes an ajax call to check some value if exists in database and returns response accordingly. The issue I am facing is when I use this for a blank form it works fine but when I am editing the form i.e. value is prefilled on page load the class rule gets executed. I think the issue is related with the document.ready but I am not able to figure out the place to put this code to stop its execution on page load.

Thanks for your time.

1 answer

  • answered 2017-08-12 09:38 SMA

    Can you try adding the validation on form submit?

       jQuery.validator.addClassRules("checkDuplicate", {checkDuplicate: true});

    Replace "#formId" with the formId you are using in your html.