Browse Source

#205: Allow to call plugin method using .bootstrapValidator('method', params)

nghuuphuoc 11 years ago
parent
commit
6f5713ad23
5 changed files with 24 additions and 13 deletions
  1. 1 0
      CHANGELOG.md
  2. 1 1
      README.md
  3. 10 5
      dist/js/bootstrapValidator.js
  4. 2 2
      dist/js/bootstrapValidator.min.js
  5. 10 5
      src/js/bootstrapValidator.js

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@
 
 
 * [#198](https://github.com/nghuuphuoc/bootstrapvalidator/pull/198): Add Canadian Postal Code support for the [```zipCode``` validator](http://bootstrapvalidator.com/validators/zip-code/), thanks to [@Francismori7](https://github.com/Francismori7)
 * [#198](https://github.com/nghuuphuoc/bootstrapvalidator/pull/198): Add Canadian Postal Code support for the [```zipCode``` validator](http://bootstrapvalidator.com/validators/zip-code/), thanks to [@Francismori7](https://github.com/Francismori7)
 * [#202](https://github.com/nghuuphuoc/bootstrapvalidator/issues/202): Activate tab containing the first invalid field
 * [#202](https://github.com/nghuuphuoc/bootstrapvalidator/issues/202): Activate tab containing the first invalid field
+* [#205](https://github.com/nghuuphuoc/bootstrapvalidator/issues/205): Plugin method invocation
 
 
 ## v0.4.2 (2014-04-19)
 ## v0.4.2 (2014-04-19)
 
 

+ 1 - 1
README.md

@@ -96,8 +96,8 @@ Big thanks to the contributors:
 * [@jswale](https://github.com/jswale)
 * [@jswale](https://github.com/jswale)
 * [@narutosanjiv](https://github.com/narutosanjiv)
 * [@narutosanjiv](https://github.com/narutosanjiv)
 * [@patmoore](https://github.com/patmoore)
 * [@patmoore](https://github.com/patmoore)
-* [@vaz](https://github.com/vaz)
 * [@tomByrer](https://github.com/tomByrer)
 * [@tomByrer](https://github.com/tomByrer)
+* [@vaz](https://github.com/vaz)
 * ... might be you! Let's [fork](https://github.com/nghuuphuoc/bootstrapvalidator/fork) and pull a request!
 * ... might be you! Let's [fork](https://github.com/nghuuphuoc/bootstrapvalidator/fork) and pull a request!
 
 
 > If you submit new RegEx, please build it using [RegExr.com](http://regexr.com/), add several tests that pass and fail there,
 > If you submit new RegEx, please build it using [RegExr.com](http://regexr.com/), add several tests that pass and fail there,

+ 10 - 5
dist/js/bootstrapValidator.js

@@ -767,14 +767,19 @@
     };
     };
 
 
     // Plugin definition
     // Plugin definition
-    $.fn.bootstrapValidator = function(options) {
+    $.fn.bootstrapValidator = function(option, params) {
         return this.each(function() {
         return this.each(function() {
-            var $this = $(this), data = $this.data('bootstrapValidator');
+            var $this   = $(this),
+                data    = $this.data('bootstrapValidator'),
+                options = 'object' == typeof option && option;
             if (!data) {
             if (!data) {
-                $this.data('bootstrapValidator', (data = new BootstrapValidator(this, options)));
+                data = new BootstrapValidator(this, options);
+                $this.data('bootstrapValidator', data);
             }
             }
-            if ('string' == typeof options) {
-                data[options]();
+
+            // Allow to call plugin method
+            if ('string' == typeof option) {
+                data[option](params);
             }
             }
         });
         });
     };
     };

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


+ 10 - 5
src/js/bootstrapValidator.js

@@ -766,14 +766,19 @@
     };
     };
 
 
     // Plugin definition
     // Plugin definition
-    $.fn.bootstrapValidator = function(options) {
+    $.fn.bootstrapValidator = function(option, params) {
         return this.each(function() {
         return this.each(function() {
-            var $this = $(this), data = $this.data('bootstrapValidator');
+            var $this   = $(this),
+                data    = $this.data('bootstrapValidator'),
+                options = 'object' == typeof option && option;
             if (!data) {
             if (!data) {
-                $this.data('bootstrapValidator', (data = new BootstrapValidator(this, options)));
+                data = new BootstrapValidator(this, options);
+                $this.data('bootstrapValidator', data);
             }
             }
-            if ('string' == typeof options) {
-                data[options]();
+
+            // Allow to call plugin method
+            if ('string' == typeof option) {
+                data[option](params);
             }
             }
         });
         });
     };
     };