我用的是第三方工具
当我输入下面的内容时,它显示了一个消息框。工具验证的自定义验证失败。我假设它也使用"showError“。我理解这是一个很难问的问题,没有完整的代码库。我的问题是..。
是否有在showErrors之后发生的事件。或者是否有一种方法可以扩展到此功能,而不是覆盖它。
$.validator.setDefaults({
showErrors: function (errorMap, errorList) {
$(".messagebox").show();
}
});发布于 2013-06-27 14:39:57
您是否试图保留默认错误显示并添加自己的错误?如果是这样,只需将this.defaultShowErrors();添加到自定义处理程序中即可。
$.validator.setDefaults({
showErrors: function (errorMap, errorList) {
$(".messagebox").show();
this.defaultShowErrors();
}
});发布于 2013-05-03 15:20:01
是否有在
showErrors之后发生的事件。
有关所有回调函数,请参见文档:
http://docs.jquery.com/Plugins/Validation/validate#toptions
或者是否有一种方法可以扩展到此功能,而不是覆盖它。
不是的。使用您的自定义回调函数(过载)是典型的方法来做到这一点。
查看插件内部;它检查是否声明了自定义回调函数,然后使用您的函数代替默认的.
// 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();
}https://stackoverflow.com/questions/16355151
复制相似问题