浏览代码

#102: The ```resetForm``` method now only resets fields with validator rules

nghuuphuoc 11 年之前
父节点
当前提交
3efc4dd86f
共有 5 个文件被更改,包括 33 次插入24 次删除
  1. 3 2
      CHANGELOG.md
  2. 5 5
      demo/index.html
  3. 12 8
      dist/js/bootstrapValidator.js
  4. 1 1
      dist/js/bootstrapValidator.min.js
  5. 12 8
      src/js/bootstrapValidator.js

+ 3 - 2
CHANGELOG.md

@@ -7,14 +7,15 @@ Not released yet
 __New features__:
 
 * [#4: Add ```date``` validator](https://github.com/nghuuphuoc/bootstrapvalidator/issues/4)
-* [#72, #79: Add ```setNotValidated()``` method to make the plugin play well with another](https://github.com/nghuuphuoc/bootstrapvalidator/issues/72)
+* [#72, #79: Improve ```updateStatus()``` method to make the plugin play well with another](https://github.com/nghuuphuoc/bootstrapvalidator/issues/72)
 * [#80: Add ```enabled``` option and  ```enableFieldValidators()``` method to enable/disable all validators to given field](https://github.com/nghuuphuoc/bootstrapvalidator/issues/80)
 * [#90: Add ```bower.json``` file](https://github.com/nghuuphuoc/bootstrapvalidator/pull/90), thanks to [@ikanedo](https://github.com/ikanedo)
 * [#3, #92: Support more form controls on the same row](https://github.com/nghuuphuoc/bootstrapvalidator/issues/92)
 
 __Changes__:
 
-* Remove the ```columns``` option
+* Remove the ```columns``` option. Now the plugin works normally no matter how many columns the form uses
+* [#102: The ```resetForm``` method now only resets fields with validator rules](https://github.com/nghuuphuoc/bootstrapvalidator/issues/102)
 
 __Fixes__:
 

+ 5 - 5
demo/index.html

@@ -199,11 +199,11 @@ $(document).ready(function() {
     $('#defaultForm').bootstrapValidator({
 //        live: 'disabled',
         message: 'This value is not valid',
-//        feedbackIcons: {
-//            valid: 'glyphicon glyphicon-ok',
-//            invalid: 'glyphicon glyphicon-remove',
-//            validating: 'glyphicon glyphicon-refresh'
-//        },
+        feedbackIcons: {
+            valid: 'glyphicon glyphicon-ok',
+            invalid: 'glyphicon glyphicon-remove',
+            validating: 'glyphicon glyphicon-refresh'
+        },
         fields: {
             firstName: {
                 validators: {

+ 12 - 8
dist/js/bootstrapValidator.js

@@ -17,8 +17,9 @@
         this.dfds    = {};      // Array of deferred
         this.results = {};      // Validating results
 
-        this.invalidField  = null;  // First invalid field
-        this.$submitButton = null;  // The submit button which is clicked to submit form
+        this.invalidField   = null; // First invalid field
+        this.$submitButton  = null; // The submit button which is clicked to submit form
+        this.originalValues = {};   // Original field values
 
         this._init();
 
@@ -471,12 +472,19 @@
          * @return {BootstrapValidator}
          */
         resetForm: function(resetFormData) {
-            for (var field in this.options.fields) {
+            var field, $field, type;
+            for (field in this.options.fields) {
                 this.dfds[field]    = {};
                 this.results[field] = {};
 
+                $field = this.getFieldElements(field);
                 // Mark field as not validated yet
-                this.updateStatus(field, this.STATUS_NOT_VALIDATED, null);
+                this.updateStatus($field, this.STATUS_NOT_VALIDATED, null);
+
+                if (resetFormData) {
+                    type = $field.attr('type');
+                    ('radio' == type || 'checkbox' == type) ? $field.removeAttr('checked').removeAttr('selected') : $field.val('');
+                }
             }
 
             this.invalidField  = null;
@@ -485,10 +493,6 @@
             // Enable submit buttons
             this._disableSubmitButtons(false);
 
-            if (resetFormData) {
-                this.$form.get(0).reset();
-            }
-
             return this;
         },
 

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


+ 12 - 8
src/js/bootstrapValidator.js

@@ -16,8 +16,9 @@
         this.dfds    = {};      // Array of deferred
         this.results = {};      // Validating results
 
-        this.invalidField  = null;  // First invalid field
-        this.$submitButton = null;  // The submit button which is clicked to submit form
+        this.invalidField   = null; // First invalid field
+        this.$submitButton  = null; // The submit button which is clicked to submit form
+        this.originalValues = {};   // Original field values
 
         this._init();
 
@@ -470,12 +471,19 @@
          * @return {BootstrapValidator}
          */
         resetForm: function(resetFormData) {
-            for (var field in this.options.fields) {
+            var field, $field, type;
+            for (field in this.options.fields) {
                 this.dfds[field]    = {};
                 this.results[field] = {};
 
+                $field = this.getFieldElements(field);
                 // Mark field as not validated yet
-                this.updateStatus(field, this.STATUS_NOT_VALIDATED, null);
+                this.updateStatus($field, this.STATUS_NOT_VALIDATED, null);
+
+                if (resetFormData) {
+                    type = $field.attr('type');
+                    ('radio' == type || 'checkbox' == type) ? $field.removeAttr('checked').removeAttr('selected') : $field.val('');
+                }
             }
 
             this.invalidField  = null;
@@ -484,10 +492,6 @@
             // Enable submit buttons
             this._disableSubmitButtons(false);
 
-            if (resetFormData) {
-                this.$form.get(0).reset();
-            }
-
             return this;
         },