浏览代码

Add init.field.bv event

phuoc 11 年之前
父节点
当前提交
b51775755c
共有 3 个文件被更改,包括 24 次插入18 次删除
  1. 11 8
      dist/js/bootstrapValidator.js
  2. 2 2
      dist/js/bootstrapValidator.min.js
  3. 11 8
      src/js/bootstrapValidator.js

+ 11 - 8
dist/js/bootstrapValidator.js

@@ -395,6 +395,11 @@
                     });
                     break;
             }
+
+            this.$form.trigger($.Event('init.field.bv'), {
+                field: field,
+                element: fields
+            });
         },
 
         /**
@@ -517,13 +522,11 @@
                                     return item + '.live.bv';
                                 }).join(' ');
 
-                            for (var i = 0; i < fields.length; i++) {
-                                fields.eq(i).off(events).on(events, function() {
-                                    if (that._exceedThreshold($(this))) {
-                                        that.validateField($(this));
-                                    }
-                                });
-                            }
+                            fields.off(events).on(events, function() {
+                                if (that._exceedThreshold($(this))) {
+                                    that.validateField($(this));
+                                }
+                            });
                         }
                     })(field);
                 }
@@ -1033,7 +1036,7 @@
                     var f = this.getFieldElements(field);
                     if (f.length > 0) {
                         var type = f.attr('type');
-                        $fields = ('radio' == type || 'checkbox' == type) ? $(f[0]) : f;
+                        $fields = ('radio' == type || 'checkbox' == type) ? f.eq(0) : f;
                     }
                     break;
                 default:

文件差异内容过多而无法显示
+ 2 - 2
dist/js/bootstrapValidator.min.js


+ 11 - 8
src/js/bootstrapValidator.js

@@ -394,6 +394,11 @@
                     });
                     break;
             }
+
+            this.$form.trigger($.Event('init.field.bv'), {
+                field: field,
+                element: fields
+            });
         },
 
         /**
@@ -516,13 +521,11 @@
                                     return item + '.live.bv';
                                 }).join(' ');
 
-                            for (var i = 0; i < fields.length; i++) {
-                                fields.eq(i).off(events).on(events, function() {
-                                    if (that._exceedThreshold($(this))) {
-                                        that.validateField($(this));
-                                    }
-                                });
-                            }
+                            fields.off(events).on(events, function() {
+                                if (that._exceedThreshold($(this))) {
+                                    that.validateField($(this));
+                                }
+                            });
                         }
                     })(field);
                 }
@@ -1032,7 +1035,7 @@
                     var f = this.getFieldElements(field);
                     if (f.length > 0) {
                         var type = f.attr('type');
-                        $fields = ('radio' == type || 'checkbox' == type) ? $(f[0]) : f;
+                        $fields = ('radio' == type || 'checkbox' == type) ? f.eq(0) : f;
                     }
                     break;
                 default: