是否有showErrors
後發生的事件。
所有回調函數見文檔:
http://docs.jquery.com/Plugins/Validation/validate#toptions
還是有辦法來擴展這個功能,而不是覆蓋 它。
否。使用自定義回調函數(over-ride)是執行此操作的典型方法。
Looking inside the plugin;它會檢查,如果你有一個自定義的回調函數聲明,然後用你的,而不是默認的...
// http://docs.jquery.com/Plugins/Validation/Validator/showErrors
showErrors: function(errors) {
if (errors) {
// add items to error list and map
$.extend(this.errorMap, errors);
this.errorList = [];
for (var name in errors) {
this.errorList.push({
message: errors[name],
element: this.findByName(name)[0]
});
}
// remove items from success list
this.successList = $.grep(this.successList, function(element) {
return !(element.name in errors);
});
}
if (this.settings.showErrors) {
this.settings.showErrors.call(this, this.errorMap, this.errorList);
} else {
this.defaultShowErrors();
}
}
defaultShowErrors: function() {
var i, elements;
for (i = 0; this.errorList[i]; i++) {
var error = this.errorList[i];
if (this.settings.highlight) {
this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass);
}
this.showLabel(error.element, error.message);
}
if (this.errorList.length) {
this.toShow = this.toShow.add(this.containers);
}
if (this.settings.success) {
for (i = 0; this.successList[i]; i++) {
this.showLabel(this.successList[i]);
}
}
if (this.settings.unhighlight) {
for (i = 0, elements = this.validElements(); elements[i]; i++) {
this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
}
}
this.toHide = this.toHide.not(this.toShow);
this.hideErrors();
this.addWrapper(this.toShow).show();
}