nghuuphuoc 12 年 前
コミット
8f8271b480

+ 27 - 21
CHANGELOG.md

@@ -1,28 +1,34 @@
 # Change Log
 
-v0.2.2
-* #31: remote validator: Allow to set additional data to remote URL
-
-v0.2.1 (2013-11-08)
-* #29: Upgrade Bootstrap to v3.0.2
-* #30: Hide the error block containers before validating
-
-v0.2.0 (2013-10-21)
-* #9: Add ```creditCard``` validator
-* #18: Add ```different``` validator
-* #20: Add custom submit handler (using ```submitHandler``` option)
-* #21: Add ```callback``` validator
-* #22: Support form that labels are placed in extra small (col-xs-), small (col-sm-), medium (col-md-) elements
-* #24: Add ```live``` option
-* #25: The ```regexp``` validator does not work
-
-v0.1.1 (2013-10-17)
+## v0.2.2
+
+* Fixed #34: Avoid from calling form submit recursively
+* Improved #31: remote validator: Allow to set additional data to remote URL
+
+##v0.2.1 (2013-11-08)
+
+* Fixed #29: Upgrade Bootstrap to v3.0.2
+* Fixed #30: Hide the error block containers before validating
+
+## v0.2.0 (2013-10-21)
+
+* Added #9: Add ```creditCard``` validator
+* Added #18: Add ```different``` validator
+* Added #20: Add custom submit handler (using ```submitHandler``` option)
+* Added #21: Add ```callback``` validator
+* Added #24: Add ```live``` option
+* Fixed #25: The ```regexp``` validator does not work
+* Improved #22: Support form that labels are placed in extra small (col-xs-), small (col-sm-), medium (col-md-) elements
+
+## v0.1.1 (2013-10-17)
+
 * Add ```submitButtons``` option
-* #16: Disable client side validation in HTML 5
-* #17: Support default Bootstrap form without labels
-* #19: Support select box validator
+* Added #17: Support default Bootstrap form without labels
+* Added #19: Support select box validator
+* Fixed #16: Disable client side validation in HTML 5
+
+## v0.1.0 (2013-10-14)
 
-v0.1.0 (2013-10-14)
 * First release
 * Provide various validators
     - between

+ 1 - 0
demo/submitHandler.html

@@ -64,6 +64,7 @@
                 // validator is the BootstrapValidator instance
                 // form is the jQuery object present the current form
                 form.find('.alert').html('Thanks for signing up. Now you can sign in as ' + validator.getFieldElement('username').val()).show();
+                form.submit();
             },
             fields: {
                 username: {

+ 16 - 5
dist/js/bootstrapValidator.js

@@ -18,10 +18,11 @@
             this.options.submitButtons = null;
         }
 
-        this.invalidFields      = {};
-        this.xhrRequests        = {};
-        this.numPendingRequests = null;
-        this.formSubmited       = false;
+        this.invalidFields       = {};
+        this.xhrRequests         = {};
+        this.numPendingRequests  = null;
+        this.formSubmited        = false;
+        this.submitHandlerCalled = false;
 
         this._init();
     };
@@ -94,7 +95,10 @@
 
                             e.preventDefault();
                         } else {
-                            if (that.options.submitHandler && 'function' == typeof that.options.submitHandler) {
+                            if (!that.submitHandlerCalled && that.options.submitHandler && 'function' == typeof that.options.submitHandler) {
+                                // Avoid calling submitHandler recursively
+                                // in the case user call form.submit() right inside the submitHandler()
+                                that.submitHandlerCalled = true;
                                 that.options.submitHandler.call(that, that, that.$form);
                                 return false;
                             }
@@ -201,6 +205,13 @@
         },
 
         /**
+         * Validate the form
+         */
+        validate: function() {
+
+        },
+
+        /**
          * Validate given field
          *
          * @param {String} field The field name

ファイルの差分が大きいため隠しています
+ 1 - 1
dist/js/bootstrapValidator.min.js


+ 16 - 5
src/js/bootstrapValidator.js

@@ -18,10 +18,11 @@
             this.options.submitButtons = null;
         }
 
-        this.invalidFields      = {};
-        this.xhrRequests        = {};
-        this.numPendingRequests = null;
-        this.formSubmited       = false;
+        this.invalidFields       = {};
+        this.xhrRequests         = {};
+        this.numPendingRequests  = null;
+        this.formSubmited        = false;
+        this.submitHandlerCalled = false;
 
         this._init();
     };
@@ -94,7 +95,10 @@
 
                             e.preventDefault();
                         } else {
-                            if (that.options.submitHandler && 'function' == typeof that.options.submitHandler) {
+                            if (!that.submitHandlerCalled && that.options.submitHandler && 'function' == typeof that.options.submitHandler) {
+                                // Avoid calling submitHandler recursively
+                                // in the case user call form.submit() right inside the submitHandler()
+                                that.submitHandlerCalled = true;
                                 that.options.submitHandler.call(that, that, that.$form);
                                 return false;
                             }
@@ -201,6 +205,13 @@
         },
 
         /**
+         * Validate the form
+         */
+        validate: function() {
+
+        },
+
+        /**
          * Validate given field
          *
          * @param {String} field The field name