Browse Source

Fix #672: The zipCode validator throw an exception when passing not supported country code

Phuoc Nguyen 11 years ago
parent
commit
26cf346b4c

+ 1 - 0
CHANGELOG.md

@@ -27,6 +27,7 @@ __Improvements__
 __Bug Fixes__
 
 * [#550](https://github.com/nghuuphuoc/bootstrapvalidator/issues/550), [#551](https://github.com/nghuuphuoc/bootstrapvalidator/pull/551): Cannot validate against both ipv4 and ipv6 at the same time, thanks to [@beeglebug](https://github.com/beeglebug)
+* [#672](https://github.com/nghuuphuoc/bootstrapvalidator/issues/672): The zipCode validator throw an exception when passing not supported country code
 
 __Language Packages__
 

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.1-dev, built on 2014-08-16 8:28:27 AM
+ * @version     v0.5.1-dev, built on 2014-08-16 10:03:02 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 4 - 3
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.1-dev, built on 2014-08-16 8:28:27 AM
+ * @version     v0.5.1-dev, built on 2014-08-16 10:03:02 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -1464,7 +1464,7 @@
                 }
                 // ... return value of callback
                 else {
-                    return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]);
+                    return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]) || option;
                 }
             }
 
@@ -1689,7 +1689,8 @@
                 for (var i = 0; i < ns.length; i++) {
                     context = context[ns[i]];
                 }
-                return context[func].apply(this, args);
+
+                return (typeof context[func] === 'undefined') ? null : context[func].apply(this, args);
             }
         },
 

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


+ 3 - 2
src/js/bootstrapValidator.js

@@ -1463,7 +1463,7 @@
                 }
                 // ... return value of callback
                 else {
-                    return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]);
+                    return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]) || option;
                 }
             }
 
@@ -1688,7 +1688,8 @@
                 for (var i = 0; i < ns.length; i++) {
                     context = context[ns[i]];
                 }
-                return context[func].apply(this, args);
+
+                return (typeof context[func] === 'undefined') ? null : context[func].apply(this, args);
             }
         },
 

+ 14 - 0
test/spec.js

@@ -5053,4 +5053,18 @@ describe('zipCode', function() {
         expect($('#msg').html()).toEqual('getCountryCode() called');
         expect(this.bv.isValid()).toBeTruthy();
     });
+
+    it('not supported country code', function() {
+        this.$zipCode.attr('data-bv-zipcode-country', 'NOT_SUPPORTED');
+
+        $('#zipCodeForm').bootstrapValidator('destroy');
+
+        this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
+
+        this.bv.resetForm();
+        this.$zipCode.val('1234');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+        expect(this.bv.getMessages(this.$zipCode, 'zipCode')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, 'NOT_SUPPORTED'));
+    });
 });

+ 14 - 0
test/spec/validator/zipCode.js

@@ -188,4 +188,18 @@ describe('zipCode', function() {
         expect($('#msg').html()).toEqual('getCountryCode() called');
         expect(this.bv.isValid()).toBeTruthy();
     });
+
+    it('not supported country code', function() {
+        this.$zipCode.attr('data-bv-zipcode-country', 'NOT_SUPPORTED');
+
+        $('#zipCodeForm').bootstrapValidator('destroy');
+
+        this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
+
+        this.bv.resetForm();
+        this.$zipCode.val('1234');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+        expect(this.bv.getMessages(this.$zipCode, 'zipCode')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, 'NOT_SUPPORTED'));
+    });
 });