Browse Source

#44: Fix isValid() method

nghuuphuoc 11 years ago
parent
commit
08769f5ef8
1 changed files with 7 additions and 5 deletions
  1. 7 5
      src/js/bootstrapValidator.js

+ 7 - 5
src/js/bootstrapValidator.js

@@ -70,6 +70,8 @@
                 return;
                 return;
             }
             }
 
 
+            this._dfds[field] = {};
+
             var fields = this.$form.find('[name="' + field + '"]');
             var fields = this.$form.find('[name="' + field + '"]');
             if (fields.length == 0) {
             if (fields.length == 0) {
                 // We don't need to validate non-existing fields next time
                 // We don't need to validate non-existing fields next time
@@ -78,8 +80,6 @@
                 return;
                 return;
             }
             }
 
 
-            this._dfds[field] = {};
-
             // Create a help block element for showing the error
             // Create a help block element for showing the error
             var $field    = $(fields[0]),
             var $field    = $(fields[0]),
                 $parent   = $field.parents('.form-group'),
                 $parent   = $field.parents('.form-group'),
@@ -193,13 +193,15 @@
          * @returns {Boolean}
          * @returns {Boolean}
          */
          */
         isValid: function() {
         isValid: function() {
-            var field;
+            var field, validatorName;
             for (field in this._invalidFields) {
             for (field in this._invalidFields) {
                 return false;
                 return false;
             }
             }
             for (field in this._dfds) {
             for (field in this._dfds) {
-                if ('pending' == this._dfds[field].state()) {
-                    return false;
+                for (validatorName in this._dfds[field]) {
+                    if ('pending' == this._dfds[field][validatorName].state()) {
+                        return false;
+                    }
                 }
                 }
             }
             }