jQuery Validation - Hide Error Message

后端 未结 10 1697
醉梦人生
醉梦人生 2021-02-05 03:39

I\'m using the jQuery Validation plugin and want to disable the or element/container it creates to display the error \'message\'.

Basically, I want the input element wi

10条回答
  •  暖寄归人
    2021-02-05 04:05

    You could set the showErrors option to a function that only performs element highlighting:

    $("selector").validate({
        showErrors: function() {
            if (this.settings.highlight) {
                for (var i = 0; this.errorList[i]; ++i) {
                    this.settings.highlight.call(this, this.errorList[i].element,
                        this.settings.errorClass, this.settings.validClass);
                }
            }
            if (this.settings.unhighlight) {
                for (var i = 0, elements = this.validElements(); elements[i]; ++i) {
                    this.settings.unhighlight.call(this, elements[i],
                        this.settings.errorClass, this.settings.validClass);
                }
            }
        }
    });
    

    That relies heavily on the validation plugin's internals, though, so it's probably not safe. The best would be for the plugin to expose a defaultHighlightElements() method the same way it does for defaultShowErrors(), but it's not the case (yet).

提交回复
热议问题