Jquery Validation: Call Valid without displaying errors?

后端 未结 2 626
灰色年华
灰色年华 2020-12-24 14:02

Using JQuery Validation plugin, I am trying to call the .valid() method without the side-effects of displaying error messages on screen. I have tried a number of scenarios w

2条回答
  •  天命终不由人
    2020-12-24 14:21

    You can do this without using CSS hacks by calling checkForm().

    var isValid = $('#signup').validate().checkForm(); // true|false
    

    checkForm() does not trigger UI changes.

    However, there is one side effect. Form fields will now be validated on change/focus/blur, which may be undesirable. You can disable this behavior by resetting the submitted object:

    $('#signup').validate().submitted = {};
    

    Which results in:

    var validate = $('#signup').validate(); // Get validate instance
    var isValid = validate.checkForm(); // Valid?
    validate.submitted = {}; // Reset immediate form field checking mode
    

提交回复
热议问题