nghuuphuoc 11 年之前
父节点
当前提交
d2b47b3ef9
共有 2 个文件被更改,包括 19 次插入22 次删除
  1. 16 16
      demo/index.html
  2. 3 6
      src/js/bootstrapValidator.js

+ 16 - 16
demo/index.html

@@ -183,18 +183,18 @@ $(document).ready(function() {
             username: {
             username: {
                 message: 'The username is not valid',
                 message: 'The username is not valid',
                 validators: {
                 validators: {
-//                    notEmpty: {
-//                        message: 'The username is required and can\'t be empty'
-//                    },
-//                    stringLength: {
-//                        min: 6,
-//                        max: 30,
-//                        message: 'The username must be more than 6 and less than 30 characters long'
-//                    },
-//                    regexp: {
-//                        regexp: /^[a-zA-Z0-9_\.]+$/,
-//                        message: 'The username can only consist of alphabetical, number, dot and underscore'
-//                    },
+                    notEmpty: {
+                        message: 'The username is required and can\'t be empty'
+                    },
+                    stringLength: {
+                        min: 6,
+                        max: 30,
+                        message: 'The username must be more than 6 and less than 30 characters long'
+                    },
+                    regexp: {
+                        regexp: /^[a-zA-Z0-9_\.]+$/,
+                        message: 'The username can only consist of alphabetical, number, dot and underscore'
+                    },
                     remote: {
                     remote: {
                         url: 'remote.php',
                         url: 'remote.php',
                         message: 'The username is not available'
                         message: 'The username is not available'
@@ -221,10 +221,10 @@ $(document).ready(function() {
                         field: 'confirmPassword',
                         field: 'confirmPassword',
                         message: 'The password and its confirm are not the same'
                         message: 'The password and its confirm are not the same'
                     },
                     },
-//                    different: {
-//                        field: 'username',
-//                        message: 'The password can\'t be the same as username'
-//                    }
+                    different: {
+                        field: 'username',
+                        message: 'The password can\'t be the same as username'
+                    }
                 }
                 }
             },
             },
             confirmPassword: {
             confirmPassword: {

+ 3 - 6
src/js/bootstrapValidator.js

@@ -355,7 +355,8 @@
          * Can be STATUS_VALIDATING, STATUS_INVALID, STATUS_VALID
          * Can be STATUS_VALIDATING, STATUS_INVALID, STATUS_VALID
          */
          */
         updateStatus: function($field, validatorName, status) {
         updateStatus: function($field, validatorName, status) {
-            var field     = $field.attr('name'),
+            var that      = this,
+                field     = $field.attr('name'),
                 validator = this.options.fields[field].validators[validatorName],
                 validator = this.options.fields[field].validators[validatorName],
                 message   = validator.message || this.options.message,
                 message   = validator.message || this.options.message,
                 $parent   = $field.parents('.form-group'),
                 $parent   = $field.parents('.form-group'),
@@ -383,10 +384,7 @@
                     // Add has-error class to parent element
                     // Add has-error class to parent element
                     $parent.removeClass('has-success').addClass('has-error');
                     $parent.removeClass('has-success').addClass('has-error');
 
 
-                    $errors
-                        .filter('[data-bs-validator="' + validatorName + '"]')
-                            .html(message)
-                            .show();
+                    $errors.filter('[data-bs-validator="' + validatorName + '"]').html(message).show();
 
 
                     if (this.options.feedbackIcons) {
                     if (this.options.feedbackIcons) {
                         // Show "error" icon
                         // Show "error" icon
@@ -401,7 +399,6 @@
                     $errors.filter('[data-bs-validator="' + validatorName + '"]').hide();
                     $errors.filter('[data-bs-validator="' + validatorName + '"]').hide();
 
 
                     // If the field is valid
                     // If the field is valid
-                    var that = this;
                     if ($errors.filter(function() {
                     if ($errors.filter(function() {
                             var display = $(this).css('display'), v = $(this).attr('data-bs-validator');
                             var display = $(this).css('display'), v = $(this).attr('data-bs-validator');
                             return ('block' == display) || (that.results[field][v] != that.STATUS_VALID);
                             return ('block' == display) || (that.results[field][v] != that.STATUS_VALID);