浏览代码

#126: Don't disable the submit button when calling custom submit handler

nghuuphuoc 12 年之前
父节点
当前提交
c6b47355cd
共有 3 个文件被更改,包括 47 次插入45 次删除
  1. 23 22
      dist/js/bootstrapValidator.js
  2. 1 1
      dist/js/bootstrapValidator.min.js
  3. 23 22
      src/js/bootstrapValidator.js

+ 23 - 22
dist/js/bootstrapValidator.js

@@ -318,20 +318,6 @@
         },
 
         /**
-         * Disable/Enable submit buttons
-         *
-         * @param {Boolean} disabled
-         */
-        _disableSubmitButtons: function(disabled) {
-            if (!disabled) {
-                this.$form.find(this.options.submitButtons).removeAttr('disabled');
-            } else if (this.options.live != 'disabled') {
-                // Don't disable if the live validating mode is disabled
-                this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
-            }
-        },
-
-        /**
          * Called when all validations are completed
          */
         _submit: function() {
@@ -348,14 +334,14 @@
                 return;
             }
 
-            this._disableSubmitButtons(true);
-
             // Call the custom submission if enabled
             if (this.options.submitHandler && 'function' == typeof this.options.submitHandler) {
                 // Turn off the submit handler, so user can call form.submit() inside their submitHandler method
                 this.$form.off('submit.bv');
                 this.options.submitHandler.call(this, this, this.$form, this.$submitButton);
             } else {
+                this.disableSubmitButtons(true);
+
                 // Submit form
                 this.$form.off('submit.bv').submit();
             }
@@ -364,6 +350,20 @@
         // --- Public methods ---
 
         /**
+         * Disable/Enable submit buttons
+         *
+         * @param {Boolean} disabled
+         */
+        disableSubmitButtons: function(disabled) {
+            if (!disabled) {
+                this.$form.find(this.options.submitButtons).removeAttr('disabled');
+            } else if (this.options.live != 'disabled') {
+                // Don't disable if the live validating mode is disabled
+                this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
+            }
+        },
+
+        /**
          * Retrieve the field elements by given name
          *
          * @param {String} field The field name
@@ -383,7 +383,7 @@
             if (!this.options.fields) {
                 return this;
             }
-            this._disableSubmitButtons(true);
+            this.disableSubmitButtons(true);
 
             for (var field in this.options.fields) {
                 this.validateField(field);
@@ -518,7 +518,7 @@
             // Show/hide error elements and feedback icons
             switch (status) {
                 case this.STATUS_VALIDATING:
-                    this._disableSubmitButtons(true);
+                    this.disableSubmitButtons(true);
                     $parent.removeClass('has-success').removeClass('has-error');
                     // TODO: Show validating message
                     validatorName ? $errors.filter('.help-block[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
@@ -528,7 +528,7 @@
                     break;
 
                 case this.STATUS_INVALID:
-                    this._disableSubmitButtons(true);
+                    this.disableSubmitButtons(true);
                     $parent.removeClass('has-success').addClass('has-error');
                     validatorName ? $errors.filter('[data-bv-validator="' + validatorName + '"]').show() : $errors.show();
                     if ($icon) {
@@ -545,12 +545,13 @@
                             return ('block' == display) || ($field.data('bv.result.' + v) != that.STATUS_VALID);
                         }).length == 0)
                     {
-                        this._disableSubmitButtons(false);
+                        this.disableSubmitButtons(false);
                         $parent.removeClass('has-error').addClass('has-success');
                         if ($icon) {
                             $icon.removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.valid).show();
                         }
                     } else {
+                        this.disableSubmitButtons(true);
                         $parent.removeClass('has-success').addClass('has-error');
                         if ($icon) {
                             $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
@@ -560,7 +561,7 @@
 
                 case this.STATUS_NOT_VALIDATED:
                 default:
-                    this._disableSubmitButtons(false);
+                    this.disableSubmitButtons(false);
                     $parent.removeClass('has-success').removeClass('has-error');
                     validatorName ? $errors.filter('.help-block[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
                     if ($icon) {
@@ -642,7 +643,7 @@
             this.$submitButton = null;
 
             // Enable submit buttons
-            this._disableSubmitButtons(false);
+            this.disableSubmitButtons(false);
 
             return this;
         },

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


+ 23 - 22
src/js/bootstrapValidator.js

@@ -317,20 +317,6 @@
         },
 
         /**
-         * Disable/Enable submit buttons
-         *
-         * @param {Boolean} disabled
-         */
-        _disableSubmitButtons: function(disabled) {
-            if (!disabled) {
-                this.$form.find(this.options.submitButtons).removeAttr('disabled');
-            } else if (this.options.live != 'disabled') {
-                // Don't disable if the live validating mode is disabled
-                this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
-            }
-        },
-
-        /**
          * Called when all validations are completed
          */
         _submit: function() {
@@ -347,14 +333,14 @@
                 return;
             }
 
-            this._disableSubmitButtons(true);
-
             // Call the custom submission if enabled
             if (this.options.submitHandler && 'function' == typeof this.options.submitHandler) {
                 // Turn off the submit handler, so user can call form.submit() inside their submitHandler method
                 this.$form.off('submit.bv');
                 this.options.submitHandler.call(this, this, this.$form, this.$submitButton);
             } else {
+                this.disableSubmitButtons(true);
+
                 // Submit form
                 this.$form.off('submit.bv').submit();
             }
@@ -363,6 +349,20 @@
         // --- Public methods ---
 
         /**
+         * Disable/Enable submit buttons
+         *
+         * @param {Boolean} disabled
+         */
+        disableSubmitButtons: function(disabled) {
+            if (!disabled) {
+                this.$form.find(this.options.submitButtons).removeAttr('disabled');
+            } else if (this.options.live != 'disabled') {
+                // Don't disable if the live validating mode is disabled
+                this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
+            }
+        },
+
+        /**
          * Retrieve the field elements by given name
          *
          * @param {String} field The field name
@@ -382,7 +382,7 @@
             if (!this.options.fields) {
                 return this;
             }
-            this._disableSubmitButtons(true);
+            this.disableSubmitButtons(true);
 
             for (var field in this.options.fields) {
                 this.validateField(field);
@@ -517,7 +517,7 @@
             // Show/hide error elements and feedback icons
             switch (status) {
                 case this.STATUS_VALIDATING:
-                    this._disableSubmitButtons(true);
+                    this.disableSubmitButtons(true);
                     $parent.removeClass('has-success').removeClass('has-error');
                     // TODO: Show validating message
                     validatorName ? $errors.filter('.help-block[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
@@ -527,7 +527,7 @@
                     break;
 
                 case this.STATUS_INVALID:
-                    this._disableSubmitButtons(true);
+                    this.disableSubmitButtons(true);
                     $parent.removeClass('has-success').addClass('has-error');
                     validatorName ? $errors.filter('[data-bv-validator="' + validatorName + '"]').show() : $errors.show();
                     if ($icon) {
@@ -544,12 +544,13 @@
                             return ('block' == display) || ($field.data('bv.result.' + v) != that.STATUS_VALID);
                         }).length == 0)
                     {
-                        this._disableSubmitButtons(false);
+                        this.disableSubmitButtons(false);
                         $parent.removeClass('has-error').addClass('has-success');
                         if ($icon) {
                             $icon.removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.valid).show();
                         }
                     } else {
+                        this.disableSubmitButtons(true);
                         $parent.removeClass('has-success').addClass('has-error');
                         if ($icon) {
                             $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
@@ -559,7 +560,7 @@
 
                 case this.STATUS_NOT_VALIDATED:
                 default:
-                    this._disableSubmitButtons(false);
+                    this.disableSubmitButtons(false);
                     $parent.removeClass('has-success').removeClass('has-error');
                     validatorName ? $errors.filter('.help-block[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
                     if ($icon) {
@@ -641,7 +642,7 @@
             this.$submitButton = null;
 
             // Enable submit buttons
-            this._disableSubmitButtons(false);
+            this.disableSubmitButtons(false);
 
             return this;
         },