Browse Source

Added a 'force submit' option for forms without their own submit button.

Forms without a submit button now won't auto-submit when the forms are valid.  Call .bootstrapValidator('submit') to force them to submit.
James Ford 11 years ago
parent
commit
f466651b5b

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
  *
- * @version     v0.5.3, built on 2014-11-05 9:14:18 PM
+ * @version     v0.5.4, built on 2014-12-11 9:05:43 AM
  * @author      https://twitter.com/nghuuphuoc
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     Commercial: http://bootstrapvalidator.com/license/
  * @license     Commercial: http://bootstrapvalidator.com/license/

+ 26 - 2
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
  *
- * @version     v0.5.3, built on 2014-11-05 9:14:18 PM
+ * @version     v0.5.4, built on 2014-12-11 9:05:43 AM
  * @author      https://twitter.com/nghuuphuoc
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     Commercial: http://bootstrapvalidator.com/license/
  * @license     Commercial: http://bootstrapvalidator.com/license/
@@ -854,6 +854,30 @@ if (typeof jQuery === 'undefined') {
                 this.validateField(field);
                 this.validateField(field);
             }
             }
 
 
+            if (this.$submitButton) {
+                this._submit();
+            }
+            this._submitIfValid = true;
+
+            return this;
+        },
+
+        /**
+         * Submit the form
+         *
+         * @returns {BootstrapValidator}
+         */
+        submit: function() {
+            if (!this.options.fields) {
+                return this;
+            }
+            this.disableSubmitButtons(true);
+
+            this._submitIfValid = false;
+            for (var field in this.options.fields) {
+                this.validateField(field);
+            }
+
             this._submit();
             this._submit();
             this._submitIfValid = true;
             this._submitIfValid = true;
 
 
@@ -935,7 +959,7 @@ if (typeof jQuery === 'undefined') {
 
 
                             that.updateStatus(updateAll ? $f.attr('data-bv-field') : $f, response.valid ? that.STATUS_VALID : that.STATUS_INVALID, v);
                             that.updateStatus(updateAll ? $f.attr('data-bv-field') : $f, response.valid ? that.STATUS_VALID : that.STATUS_INVALID, v);
 
 
-                            if (response.valid && that._submitIfValid === true) {
+                            if (response.valid && that._submitIfValid === true && that.$submitButton) {
                                 // If a remote validator returns true and the form is ready to submit, then do it
                                 // If a remote validator returns true and the form is ready to submit, then do it
                                 that._submit();
                                 that._submit();
                             } else if (!response.valid && !verbose) {
                             } else if (!response.valid && !verbose) {

File diff suppressed because it is too large
+ 2 - 2
dist/js/bootstrapValidator.min.js


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "bootstrapValidator",
     "name": "bootstrapValidator",
-    "version": "0.5.3",
+    "version": "0.5.4",
     "description": "The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3",
     "description": "The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3",
     "keywords": ["jQuery", "plugin", "validate", "validator", "form", "Bootstrap"],
     "keywords": ["jQuery", "plugin", "validate", "validator", "form", "Bootstrap"],
     "author": {
     "author": {

+ 22 - 0
src/js/bootstrapValidator.js

@@ -863,6 +863,28 @@ if (typeof jQuery === 'undefined') {
         },
         },
 
 
         /**
         /**
+         * Submit the form
+         *
+         * @returns {BootstrapValidator}
+         */
+        submit: function() {
+            if (!this.options.fields) {
+                return this;
+            }
+            this.disableSubmitButtons(true);
+
+            this._submitIfValid = false;
+            for (var field in this.options.fields) {
+                this.validateField(field);
+            }
+
+            this._submit();
+            this._submitIfValid = true;
+
+            return this;
+        },
+
+        /**
          * Validate given field
          * Validate given field
          *
          *
          * @param {String|jQuery} field The field name or field element
          * @param {String|jQuery} field The field name or field element