浏览代码

#269, #273, #447: Skip the _isExcluded() when initializing the form, thanks to @AlaskanShade

nghuuphuoc 11 年之前
父节点
当前提交
4151110869
共有 6 个文件被更改,包括 21 次插入24 次删除
  1. 1 0
      CHANGELOG.md
  2. 1 0
      README.md
  3. 1 1
      dist/css/bootstrapValidator.min.css
  4. 11 12
      dist/js/bootstrapValidator.js
  5. 4 4
      dist/js/bootstrapValidator.min.js
  6. 3 7
      src/js/bootstrapValidator.js

+ 1 - 0
CHANGELOG.md

@@ -67,6 +67,7 @@ __Bug Fixes__
 * [#401](https://github.com/nghuuphuoc/bootstrapvalidator/issues/401): [stringLength validator](http://bootstrapvalidator.com/validators/stringLength/) allows spaces after max length
 * [#411](https://github.com/nghuuphuoc/bootstrapvalidator/pull/411): Fix the [ean validator](http://bootstrapvalidator.com/validators/ean/) when the check digit is zero, thanks to [@manish-in-java](https://github.com/manish-in-java)
 * [#417](https://github.com/nghuuphuoc/bootstrapvalidator/issues/417): IPv6 validator doesn't work
+* [#447](https://github.com/nghuuphuoc/bootstrapvalidator/pull/447): Skip the ```_isExcluded()``` when initializing the form. This fixes [#273](https://github.com/nghuuphuoc/bootstrapvalidator/issues/273). Thanks to [@AlaskanShade](https://github.com/AlaskanShade)
 
 __Document__
 * [#259](https://github.com/nghuuphuoc/bootstrapvalidator/issues/259): Typo "Support almost Bootstrap forms", thanks to [@lloydde](https://github.com/lloydde)

+ 1 - 0
README.md

@@ -109,6 +109,7 @@ Big thanks to the contributors:
 
 * [@aca02djr](https://github.com/aca02djr)
 * [@adgrafik](https://github.com/adgrafik)
+* [@AlaskanShade](https://github.com/AlaskanShade)
 * [@alavers](https://github.com/alavers)
 * [@easonhan007](https://github.com/easonhan007)
 * [@emilchristensen](https://github.com/emilchristensen)

+ 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.0-dev, built on 2014-06-29 9:46:23 PM
+ * @version     v0.5.0-dev, built on 2014-07-01 8:05:04 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 11 - 12
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.0-dev, built on 2014-06-29 9:46:23 PM
+ * @version     v0.5.0-dev, built on 2014-07-01 8:05:04 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -88,13 +88,9 @@
                 // Find all fields which have either "name" or "data-bv-field" attribute
                 .find('[name], [data-bv-field]')
                     .each(function() {
-                        var $field = $(this);
-                        if (that._isExcluded($field)) {
-                            return;
-                        }
-
-                        var field = $field.attr('name') || $field.attr('data-bv-field'),
-                            opts  = that._parseOptions($field);
+                        var $field = $(this),
+                            field  = $field.attr('name') || $field.attr('data-bv-field'),
+                            opts   = that._parseOptions($field);
                         if (opts) {
                             $field.attr('data-bv-field', field);
                             options.fields[field] = $.extend({}, opts, options.fields[field]);
@@ -6117,7 +6113,8 @@
     $.fn.bootstrapValidator.validators.zipCode = {
         html5Attributes: {
             message: 'message',
-            country: 'country'
+            country: 'country',
+            countryfield: 'countryfield'
         },
 
         COUNTRIES: ['CA', 'DK', 'GB', 'IT', 'NL', 'SE', 'SG', 'US'],
@@ -6130,6 +6127,7 @@
          * @param {Object} options Consist of key:
          * - message: The invalid message
          * - country: The ISO 3166 country code
+         * - counryfield: Another field that contains the country code
          *
          * Currently it supports the following countries:
          * - US (United State)
@@ -6144,11 +6142,12 @@
          */
         validate: function(validator, $field, options) {
             var value = $field.val();
-            if (value === '' || !options.country) {
+            if (value === '' || (!options.country && !options.countryfield)) {
                 return true;
             }
 
-            var country = (options.country || 'US').toUpperCase();
+            var cField = options.countryfield ? validator.getFieldElements(options.countryfield) : null;
+            var country = (cField ? cField.val() : null || options.country || 'US').toUpperCase();
             if ($.inArray(country, this.COUNTRIES) === -1) {
                 return false;
             }
@@ -6168,7 +6167,7 @@
                 case 'SG': return /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
                 case 'US':
                 /* falls through */
-                default: return /^\d{4,5}([\-]\d{4})?$/.test(value);
+                default: return /^\d{4,5}([\-]?\d{4})?$/.test(value);
             }
         },
 

文件差异内容过多而无法显示
+ 4 - 4
dist/js/bootstrapValidator.min.js


+ 3 - 7
src/js/bootstrapValidator.js

@@ -87,13 +87,9 @@
                 // Find all fields which have either "name" or "data-bv-field" attribute
                 .find('[name], [data-bv-field]')
                     .each(function() {
-                        var $field = $(this);
-                        //if (that._isExcluded($field)) {
-                        //    return;
-                        //}
-
-                        var field = $field.attr('name') || $field.attr('data-bv-field'),
-                            opts  = that._parseOptions($field);
+                        var $field = $(this),
+                            field  = $field.attr('name') || $field.attr('data-bv-field'),
+                            opts   = that._parseOptions($field);
                         if (opts) {
                             $field.attr('data-bv-field', field);
                             options.fields[field] = $.extend({}, opts, options.fields[field]);