ソースを参照

#76: Add resetForm() method

nghuuphuoc 11 年 前
コミット
ba1b20bcad

+ 1 - 0
CHANGELOG.md

@@ -14,6 +14,7 @@ __New features__:
 * [#65: Support Sweden zip code](https://github.com/nghuuphuoc/bootstrapvalidator/issues/64)
 * [#70: Support custom grid columns](https://github.com/nghuuphuoc/bootstrapvalidator/issues/70)
 * [#71: Show all errors](https://github.com/nghuuphuoc/bootstrapvalidator/issues/71)
+* [#76: Add resetForm() method](https://github.com/nghuuphuoc/bootstrapvalidator/issues/76)
 
 __Fixes__:
 

+ 24 - 0
README.md

@@ -251,6 +251,30 @@ max         | n/a     | The maximum length. One of ```min```, ```max``` options
 | country     | US      | A ISO 3166 country code. Currently it supports the following countries:
 |             |         | US (United State), DK (Denmark), SE (Sweden)
 
+## API
+
+### ```validate()```
+
+Validate form manually. It is useful when you want to validate form by clicking a button or a link instead of a submit buttons.
+
+```javascript
+$(form).bootstrapValidator(options).bootstrapValidator('validate');
+
+// or
+var validator = $(form).bootstrapValidator(options);
+validator.validate();
+```
+
+### ```resetForm(resetFormData)```
+
+Reset form. It hide all error elements and feedback icons. All the fields are marked as not validated yet.
+If ```resetFormData``` are ```true```, the method resets the form fields.
+
+```javascript
+var validator = $(form).bootstrapValidator(options);
+validator.resetForm();
+```
+
 ## Write new validator
 
 A validator has to follow the syntax:

+ 5 - 0
demo/index.html

@@ -158,6 +158,7 @@
                             <div class="col-lg-9 col-lg-offset-3">
                                 <button type="submit" class="btn btn-primary">Sign up</button>
                                 <button type="button" class="btn btn-info" id="validateBtn">Manual validate</button>
+                                <button type="button" class="btn btn-info" id="resetBtn">Reset form</button>
                             </div>
                         </div>
                     </form>
@@ -283,6 +284,10 @@ $(document).ready(function() {
     $('#validateBtn').click(function() {
         $('#defaultForm').bootstrapValidator('validate');
     });
+
+    $('#resetBtn').click(function() {
+        $('#defaultForm').data('bootstrapValidator').resetForm(true);
+    });
 });
 </script>
 </body>

+ 1 - 1
dist/js/bootstrapValidator.js

@@ -464,7 +464,7 @@
             }
 
             if (resetFormData) {
-                this.$form.reset();
+                this.$form.get(0).reset();
             }
         }
     };

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


+ 1 - 1
src/js/bootstrapValidator.js

@@ -463,7 +463,7 @@
             }
 
             if (resetFormData) {
-                this.$form.reset();
+                this.$form.get(0).reset();
             }
         }
     };