How to clear jquery validate errors

后端 未结 6 1033
灰色年华
灰色年华 2020-12-14 10:26

I\'m hijaxing an existing form and POSTing to the server. jQuery validate does most of the validation but if validation fails on the server we return the errors to the clien

6条回答
  •  -上瘾入骨i
    2020-12-14 11:25

    Here's the code I ended up using to clear/reset all errors. It's possible there's some redundancy in there, but it's working for me.

    function removeValidationErrors(frmId) {
        var myform = $('#' + frmId);
        myform.get(0).reset();
        var myValidator = myform.validate();
        $(myform).removeData('validator');
        $(myform).removeData('unobtrusiveValidation');
        $.validator.unobtrusive.parse(myform);
        myValidator.resetForm();
        $('#' + frmId + ' input, select').removeClass('input-validation-error');
    }
    

提交回复
热议问题