浏览代码

#159, #163: User doesn't need to submit the form twice when remote validator complete

nghuuphuoc 11 年之前
父节点
当前提交
63c6e91e3d
共有 4 个文件被更改,包括 15 次插入9 次删除
  1. 2 1
      CHANGELOG.md
  2. 1 0
      README.md
  3. 6 4
      dist/js/bootstrapValidator.js
  4. 6 4
      src/js/bootstrapValidator.js

+ 2 - 1
CHANGELOG.md

@@ -7,8 +7,9 @@
 * [#131](https://github.com/nghuuphuoc/bootstrapvalidator/issues/131): Doesn't trigger validation on the first focus
 * [#145](https://github.com/nghuuphuoc/bootstrapvalidator/issues/145): The row state is now only marked as success if all fields on it are valid
 * [#157](https://github.com/nghuuphuoc/bootstrapvalidator/issues/157): Added support for element outside of form using the ```selector``` option
+* [#159](https://github.com/nghuuphuoc/bootstrapvalidator/issues/159), [#163](https://github.com/nghuuphuoc/bootstrapvalidator/pull/163): User doesn't need to submit the form twice when remote validator complete, thanks to [@jswale](https://github.com/jswale)
 * [#162](https://github.com/nghuuphuoc/bootstrapvalidator/pull/162): Fix errors in IE 8, thanks to [@adgrafik](https://github.com/adgrafik)
-* [#166](https://github.com/nghuuphuoc/bootstrapvalidator/issues/166), [#167](https://github.com/nghuuphuoc/bootstrapvalidator/pull/167): The [```phone``` validator](http://bootstrapvalidator.com/validators/phone/) checks the length of US phone number
+* [#166](https://github.com/nghuuphuoc/bootstrapvalidator/issues/166), [#167](https://github.com/nghuuphuoc/bootstrapvalidator/pull/167): The [```phone``` validator](http://bootstrapvalidator.com/validators/phone/) now also checks the length of US phone number, thanks to [@gercheq](https://github.com/gercheq)
 
 ## v0.4.0 (2014-04-03)
 

+ 1 - 0
README.md

@@ -56,6 +56,7 @@ Big thanks to the contributors:
 * [@kristian-puccio](https://github.com/kristian-puccio)
 * [@ikanedo](https://github.com/ikanedo)
 * [@iplus](https://github.com/iplus)
+* [@jswale](https://github.com/jswale)
 * [@narutosanjiv](https://github.com/narutosanjiv)
 * [@patmoore](https://github.com/patmoore)
 * [@vaz](https://github.com/vaz)

+ 6 - 4
dist/js/bootstrapValidator.js

@@ -30,7 +30,9 @@
         var el = document.createElement('div');
         this._changeEvent = ('oninput' in el) ? 'input' : 'keydown';
 
+        // The flag to indicate that the form is ready to submit when a remote/callback validator returns
         this._submitIfValid = null;
+
         this._init();
     };
 
@@ -128,7 +130,7 @@
                     that.validate();
                 })
                 .on('click', this.options.submitButtons, function() {
-                    that.$submitButton = $(this);
+                    that.$submitButton  = $(this);
 					// The user just click the submit button
 					that._submitIfValid = true;
                 })
@@ -230,7 +232,8 @@
 
                 // 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
+                    // Reset the flag
+                    that._submitIfValid = false;
                     updateAll ? that.updateStatus(field, that.STATUS_NOT_VALIDATED, null)
                               : that.updateElementStatus($(this), that.STATUS_NOT_VALIDATED, null);
                 });
@@ -481,8 +484,7 @@
                                   : that.updateElementStatus($f, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
 
                         if (isValid && that._submitIfValid == true) {
-						    // 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();
 						}
                     });

+ 6 - 4
src/js/bootstrapValidator.js

@@ -29,7 +29,9 @@
         var el = document.createElement('div');
         this._changeEvent = ('oninput' in el) ? 'input' : 'keydown';
 
+        // The flag to indicate that the form is ready to submit when a remote/callback validator returns
         this._submitIfValid = null;
+
         this._init();
     };
 
@@ -127,7 +129,7 @@
                     that.validate();
                 })
                 .on('click', this.options.submitButtons, function() {
-                    that.$submitButton = $(this);
+                    that.$submitButton  = $(this);
 					// The user just click the submit button
 					that._submitIfValid = true;
                 })
@@ -229,7 +231,8 @@
 
                 // 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
+                    // Reset the flag
+                    that._submitIfValid = false;
                     updateAll ? that.updateStatus(field, that.STATUS_NOT_VALIDATED, null)
                               : that.updateElementStatus($(this), that.STATUS_NOT_VALIDATED, null);
                 });
@@ -480,8 +483,7 @@
                                   : that.updateElementStatus($f, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
 
                         if (isValid && that._submitIfValid == true) {
-						    // 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();
 						}
                     });