Is there a function in jquery.validate that will reset a single field like resetForm does for a form?

后端 未结 6 2464
旧巷少年郎
旧巷少年郎 2021-02-18 15:59

I want to call a jquery function to manually remove errors from a single field and reset the error markup. Is there a function that does this that would be similar to the reset

6条回答
  •  轮回少年
    2021-02-18 16:19

    this resets the entire form

    var validator = $("#myform").validate();
    validator.resetForm();
    

    this will reset only the name element

    $("#skip").click(function() {
       var rules = $("#name").removeAttrs("min max"); // remove min and max
       $("#form").submit(); // submit, as there are no attributes, it will not have an error
       $("#name").attr(rules); // add it again so you can validate it
    });
    

提交回复
热议问题