Skip to content

Commit 17799c5

Browse files
committed
新增 context.label 自定义;改进默认的错误信息渲染逻辑
1 parent b81e4ac commit 17799c5

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# jQuery Validator
22

3-
当前版本: **1.3.7**
3+
当前版本: **1.3.8**
44

55
jQuery Validator 是一个简单易用、功能强大的基于jQuery的表单验证框架。其设计目标如下:
66
* 【简单易用,轻松上手】:一般情况下,无需进行任何配置,内置的校验器和校验规则即可满足绝大多数中文环境下的常规表单验证需求,开箱即可使用!
@@ -11,6 +11,6 @@ jQuery Validator 是一个简单易用、功能强大的基于jQuery的表单验
1111
## jQuery Validator 依赖
1212
jQuery 1.6+(建议采用 1.x 或 2.x 的最新版本)
1313
## jQuery Validator 初体验 & 快速入门
14-
演示示例及快速入门教程,请参见网址:[http://www.365mini.com/page/jquery-validator-quickstart.htm](http://www.365mini.com/page/jquery-validator-quickstart.htm "jQuery Validator 快速入门")
14+
演示示例及快速入门教程,请参见网址:[https://codeplayer.vip/p/j7sud](https://codeplayer.vip/p/j7sud "jQuery Validator 快速入门")
1515
## jQuery Validator 文档
16-
请参见网址:[http://www.365mini.com/page/tag/jquery-validator](http://www.365mini.com/page/tag/jquery-validator "jQuery Validator 文档")
16+
请参见网址:[https://codeplayer.vip/p/j7sus](https://codeplayer.vip/p/j7sus "jQuery Validator 文档")

jquery-validator.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**************************************
22
@Name: jQuery-Validator 基于jQuery的前端验证框架
3-
@Version: 1.3.7
3+
@Version: 1.3.8
44
@Author: Ready
5-
@Date: 2020-08-24
5+
@Date: 2021-11-12
66
@Documentation: https://codeplayer.vip/p/j7sud
77
@Email: CodePlayer360@gmail.com
88
@Licence: https://www.apache.org/licenses/LICENSE-2.0.html
@@ -36,7 +36,7 @@
3636
},
3737
fn = V.fn = V.prototype = {
3838
// 版本号
39-
version: "1.3.6",
39+
version: "1.3.8",
4040

4141
constructor: V,
4242

@@ -694,11 +694,12 @@
694694
}
695695
},
696696
// 渲染错误
697-
renderError: function(message, $target, context){
698-
if($target && $target.length && $.isFunction($target.tips)){
699-
$target.tips(message);
700-
}else {
701-
alert(message);
697+
renderError: function(msg, $target, context){
698+
if($target && $target.length && $.isFunction($target.tips) && $target.is(':visible')){
699+
// 只有可见的元素才适合使用 tips 方式渲染错误
700+
$target.tips(msg);
701+
} else {
702+
$.isFunction($.alert) ? $.alert(msg) : alert(msg);
702703
}
703704
var e = context.event;
704705
if( !e || e.type != "focusout" && e.type != "blur")
@@ -786,7 +787,7 @@
786787
getLabel: function(name, $dom, context){
787788
if(!name && $dom) name = $dom.prop("name");
788789
if(name != null){
789-
var label = this.labels[name] || fn.labels[name];
790+
var label = context.label || this.labels[name] || fn.labels[name];
790791
if(label == null && $dom && $dom.length ){
791792
label = $dom.attr(this.labelAttr || "label") || $dom.first().prev("label").text();
792793
}

0 commit comments

Comments
 (0)