如何显示在jQueryUI的提示jQueryUI的验证错误信息 [英] How to display jqueryui validation error message in jqueryui tooltip
问题描述
我下面本教程以显示jQueryUI的提示验证错误。验证工作正常,但我无法显示正确的错误消息,因为正确的属性不能被有条件地挂提示,按我下面的例子:
I am following this tutorial to display validation errors in jqueryui tooltip. The validation works fine, but I am unable to display the correct error messages as the correct attributes can not be conditionally linked to the tooltip, as per my example below:
$(document).tooltip({
items: ".input-validation-error",
content: function () {
//debugger;
return $(this).attr('data-val-required');
}
});
只有将这种逻辑显示的必填字段错误信息,有没有办法通过挖掘验证结果来扩展这个逻辑(用于远程和比较类型验证),或有我打了死胡同?
Only the required field error message will be displayed by this logic, is there a way to extend this logic by tapping into the validation results (for remote and compare type validations), or have I hit a dead-end?
推荐答案
由于内容()函数被调用需求,可以提供你需要的任何文字依据这个$的属性C $ C>这是有问题的元素。
Since the content() function is called on demand, you can supply whatever text you need based on the attributes of this
which is the element in question.
您需要检查的元素并返回所发生的验证错误的文本。是这样的:
You need to inspect the element and return the text for the validation error that occurred. Something like:
$(document).tooltip({
items: ".input-validation-error",
content: function () {
//debugger;
return $(this).attr('data-val-required') ||
$(this).attr('data-val-date') ||
$(this).attr('data-val-number'); // etc etc
}
});
这将返回填充了一条错误消息的数据验证属性。
This will return the data validation attribute that is populated with an error message.
这篇关于如何显示在jQueryUI的提示jQueryUI的验证错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!