Skip to content

Commit

Permalink
新增 context.label 自定义;改进默认的错误信息渲染逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
CodePlayer committed Nov 12, 2021
1 parent b81e4ac commit 17799c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# jQuery Validator

当前版本: **1.3.7**
当前版本: **1.3.8**

jQuery Validator 是一个简单易用、功能强大的基于jQuery的表单验证框架。其设计目标如下:
* 【简单易用,轻松上手】:一般情况下,无需进行任何配置,内置的校验器和校验规则即可满足绝大多数中文环境下的常规表单验证需求,开箱即可使用!
Expand All @@ -11,6 +11,6 @@ jQuery Validator 是一个简单易用、功能强大的基于jQuery的表单验
## jQuery Validator 依赖
jQuery 1.6+(建议采用 1.x 或 2.x 的最新版本)
## jQuery Validator 初体验 & 快速入门
演示示例及快速入门教程,请参见网址:[http://www.365mini.com/page/jquery-validator-quickstart.htm](http://www.365mini.com/page/jquery-validator-quickstart.htm "jQuery Validator 快速入门")
演示示例及快速入门教程,请参见网址:[https://codeplayer.vip/p/j7sud](https://codeplayer.vip/p/j7sud "jQuery Validator 快速入门")
## jQuery Validator 文档
请参见网址:[http://www.365mini.com/page/tag/jquery-validator](http://www.365mini.com/page/tag/jquery-validator "jQuery Validator 文档")
请参见网址:[https://codeplayer.vip/p/j7sus](https://codeplayer.vip/p/j7sus "jQuery Validator 文档")
19 changes: 10 additions & 9 deletions jquery-validator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**************************************
@Name: jQuery-Validator 基于jQuery的前端验证框架
@Version: 1.3.7
@Version: 1.3.8
@Author: Ready
@Date: 2020-08-24
@Date: 2021-11-12
@Documentation: https://codeplayer.vip/p/j7sud
@Email: [email protected]
@Licence: https://www.apache.org/licenses/LICENSE-2.0.html
Expand Down Expand Up @@ -36,7 +36,7 @@
},
fn = V.fn = V.prototype = {
// 版本号
version: "1.3.6",
version: "1.3.8",

constructor: V,

Expand Down Expand Up @@ -694,11 +694,12 @@
}
},
// 渲染错误
renderError: function(message, $target, context){
if($target && $target.length && $.isFunction($target.tips)){
$target.tips(message);
}else {
alert(message);
renderError: function(msg, $target, context){
if($target && $target.length && $.isFunction($target.tips) && $target.is(':visible')){
// 只有可见的元素才适合使用 tips 方式渲染错误
$target.tips(msg);
} else {
$.isFunction($.alert) ? $.alert(msg) : alert(msg);
}
var e = context.event;
if( !e || e.type != "focusout" && e.type != "blur")
Expand Down Expand Up @@ -786,7 +787,7 @@
getLabel: function(name, $dom, context){
if(!name && $dom) name = $dom.prop("name");
if(name != null){
var label = this.labels[name] || fn.labels[name];
var label = context.label || this.labels[name] || fn.labels[name];
if(label == null && $dom && $dom.length ){
label = $dom.attr(this.labelAttr || "label") || $dom.first().prev("label").text();
}
Expand Down
Loading

0 comments on commit 17799c5

Please sign in to comment.