浏览代码

Update bootstrapValidator.js

Jonathan Swale 11 年之前
父节点
当前提交
611dc0260f
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      src/js/bootstrapValidator.js

+ 9 - 3
src/js/bootstrapValidator.js

@@ -29,6 +29,7 @@
         var el = document.createElement('div');
         this._changeEvent = ('oninput' in el) ? 'input' : 'keydown';
 
+        this._submitIfValid = null;
         this._init();
     };
 
@@ -127,6 +128,8 @@
                 })
                 .on('click', this.options.submitButtons, function() {
                     that.$submitButton = $(this);
+					// The user just click the submit button
+					that._submitIfValid = true;
                 })
                 // Find all fields which have either "name" or "data-bv-field" attribute
                 .find('[name], [data-bv-field]').each(function() {
@@ -226,6 +229,7 @@
 
                 // Whenever the user change the field value, mark it as not validated yet
                 $field.on(event + '.update.bv', function() {
+                    that._submitIfValid = false;    // Reset the flag
                     updateAll ? that.updateStatus(field, that.STATUS_NOT_VALIDATED, null)
                               : that.updateElementStatus($(this), that.STATUS_NOT_VALIDATED, null);
                 });
@@ -475,9 +479,11 @@
                         updateAll ? that.updateStatus($f.attr('data-bv-field'), isValid ? that.STATUS_VALID : that.STATUS_INVALID, v)
                                   : that.updateElementStatus($f, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
 
-                        if (isValid && 'disabled' == that.options.live && that.$submitButton) {
-                            that._submit();
-                        }
+                        if (isValid && that._submitIfValid == true) {
+						    // If a remote validator returns true
+							// and the form is ready to submit, then do it
+							that._submit();
+						}
                     });
                 } else if ('boolean' == typeof validateResult) {
                     updateAll ? this.updateStatus(field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName)