Browse Source

#617: Add init and destroy methods to validator

phuoc 11 years ago
parent
commit
aa1ff8f2c8

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@
 
 
 __New features__
 __New features__
 * [#542](https://github.com/nghuuphuoc/bootstrapvalidator/issues/542), [#666](https://github.com/nghuuphuoc/bootstrapvalidator/pull/666): Add blank validator, thanks to [@bermo](https://github.com/bermo)
 * [#542](https://github.com/nghuuphuoc/bootstrapvalidator/issues/542), [#666](https://github.com/nghuuphuoc/bootstrapvalidator/pull/666): Add blank validator, thanks to [@bermo](https://github.com/bermo)
+* [#617](https://github.com/nghuuphuoc/bootstrapvalidator/issues/617): Add ```init``` and ```destroy``` methods to validator
 
 
 __Improvements__
 __Improvements__
 
 

+ 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.2-dev, built on 2014-08-24 4:21:22 PM
+ * @version     v0.5.2-dev, built on 2014-08-24 8:11:36 PM
  * @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     MIT
  * @license     MIT

+ 11 - 1
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.2-dev, built on 2014-08-24 4:21:22 PM
+ * @version     v0.5.2-dev, built on 2014-08-24 8:11:36 PM
  * @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     MIT
  * @license     MIT
@@ -309,6 +309,11 @@
                             .appendTo($message);
                             .appendTo($message);
                     }
                     }
 
 
+                    // Init the validator
+                    if ('function' === typeof $.fn.bootstrapValidator.validators[validatorName].init) {
+                        $.fn.bootstrapValidator.validators[validatorName].init(this, $field);
+                    }
+
                     // Prepare the validator events
                     // Prepare the validator events
                     if (this.options.fields[field].validators[validatorName].onSuccess) {
                     if (this.options.fields[field].validators[validatorName].onSuccess) {
                         $field.on(this.options.events.validatorSuccess, function(e, data) {
                         $field.on(this.options.events.validatorSuccess, function(e, data) {
@@ -1564,6 +1569,11 @@
                             $field.data('bv.dfs.' + validator).reject();
                             $field.data('bv.dfs.' + validator).reject();
                         }
                         }
                         $field.removeData('bv.result.' + validator).removeData('bv.dfs.' + validator);
                         $field.removeData('bv.result.' + validator).removeData('bv.dfs.' + validator);
+
+                        // Destroy the validator
+                        if ('function' === typeof $.fn.bootstrapValidator.validators[validator].destroy) {
+                            $.fn.bootstrapValidator.validators[validator].destroy(this, $field);
+                        }
                     }
                     }
                 }
                 }
             }
             }

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


+ 10 - 0
src/js/bootstrapValidator.js

@@ -308,6 +308,11 @@
                             .appendTo($message);
                             .appendTo($message);
                     }
                     }
 
 
+                    // Init the validator
+                    if ('function' === typeof $.fn.bootstrapValidator.validators[validatorName].init) {
+                        $.fn.bootstrapValidator.validators[validatorName].init(this, $field);
+                    }
+
                     // Prepare the validator events
                     // Prepare the validator events
                     if (this.options.fields[field].validators[validatorName].onSuccess) {
                     if (this.options.fields[field].validators[validatorName].onSuccess) {
                         $field.on(this.options.events.validatorSuccess, function(e, data) {
                         $field.on(this.options.events.validatorSuccess, function(e, data) {
@@ -1563,6 +1568,11 @@
                             $field.data('bv.dfs.' + validator).reject();
                             $field.data('bv.dfs.' + validator).reject();
                         }
                         }
                         $field.removeData('bv.result.' + validator).removeData('bv.dfs.' + validator);
                         $field.removeData('bv.result.' + validator).removeData('bv.dfs.' + validator);
+
+                        // Destroy the validator
+                        if ('function' === typeof $.fn.bootstrapValidator.validators[validator].destroy) {
+                            $.fn.bootstrapValidator.validators[validator].destroy(this, $field);
+                        }
                     }
                     }
                 }
                 }
             }
             }