Browse Source

#76: Add resetForm() method

nghuuphuoc 12 years ago
parent
commit
523086d214
3 changed files with 81 additions and 1 deletions
  1. 40 0
      dist/js/bootstrapValidator.js
  2. 1 1
      dist/js/bootstrapValidator.min.js
  3. 40 0
      src/js/bootstrapValidator.js

+ 40 - 0
dist/js/bootstrapValidator.js

@@ -426,6 +426,46 @@
                 default:
                     break;
             }
+        },
+
+        // Useful APIs which aren't use internally
+
+        /**
+         * Reset the form
+         *
+         * @param {Boolean} resetFormData Reset current form data
+         */
+        resetForm: function(resetFormData) {
+            for (var field in this.options.fields) {
+                this.dfds[field]    = {};
+                this.results[field] = {};
+
+                // Mark all fields as not validated yet
+                for (var v in this.options.fields[field].validators) {
+                    this.results[field][v] = this.STATUS_NOT_VALIDATED;
+                }
+            }
+
+            this.invalidField  = null;
+            this.$submitButton = null;
+
+            // Hide all error elements
+            this.$form
+                .find('.has-error').removeClass('has-error').end()
+                .find('.has-success').removeClass('has-success').end()
+                .find('.help-block[data-bs-validator]').hide();
+
+            // Enable submit buttons
+            this._disableSubmitButtons(false);
+
+            // Hide all feeback icons
+            if (this.options.feedbackIcons) {
+                this.$form.find('.form-control-feedback').removeClass('glyphicon-ok').removeClass('glyphicon-remove').removeClass('glyphicon-refresh').hide();
+            }
+
+            if (resetFormData) {
+                this.$form.reset();
+            }
         }
     };
 

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


+ 40 - 0
src/js/bootstrapValidator.js

@@ -425,6 +425,46 @@
                 default:
                     break;
             }
+        },
+
+        // Useful APIs which aren't use internally
+
+        /**
+         * Reset the form
+         *
+         * @param {Boolean} resetFormData Reset current form data
+         */
+        resetForm: function(resetFormData) {
+            for (var field in this.options.fields) {
+                this.dfds[field]    = {};
+                this.results[field] = {};
+
+                // Mark all fields as not validated yet
+                for (var v in this.options.fields[field].validators) {
+                    this.results[field][v] = this.STATUS_NOT_VALIDATED;
+                }
+            }
+
+            this.invalidField  = null;
+            this.$submitButton = null;
+
+            // Hide all error elements
+            this.$form
+                .find('.has-error').removeClass('has-error').end()
+                .find('.has-success').removeClass('has-success').end()
+                .find('.help-block[data-bs-validator]').hide();
+
+            // Enable submit buttons
+            this._disableSubmitButtons(false);
+
+            // Hide all feeback icons
+            if (this.options.feedbackIcons) {
+                this.$form.find('.form-control-feedback').removeClass('glyphicon-ok').removeClass('glyphicon-remove').removeClass('glyphicon-refresh').hide();
+            }
+
+            if (resetFormData) {
+                this.$form.reset();
+            }
         }
     };