浏览代码

#578, #813: Add support for HTML 5 minlength attribute, thanks to @emilchristensen

phuoc 11 年之前
父节点
当前提交
5d9200bf95

+ 1 - 0
CHANGELOG.md

@@ -24,6 +24,7 @@ __Improvements__
 * [#345](https://github.com/nghuuphuoc/bootstrapvalidator/issues/345), [#454](https://github.com/nghuuphuoc/bootstrapvalidator/pull/454): The [different](http://bootstrapvalidator.com/validators/different/) validator allows more than a 2-way comparison, thanks to [@AlaskanShade](https://github.com/AlaskanShade)
 * [#557](https://github.com/nghuuphuoc/bootstrapvalidator/issues/557), [#569](https://github.com/nghuuphuoc/bootstrapvalidator/pull/569): The [container](http://bootstrapvalidator.com/settings/#form-container) option can be defined by a callback, thanks to [@mattrick](https://github.com/mattrick)
 * [#570](https://github.com/nghuuphuoc/bootstrapvalidator/issues/570): Use CSS classes instead of inline styling to fix icons with ```input-group```, thanks to [@dlcrush](https://github.com/dlcrush)
+* [#578](https://github.com/nghuuphuoc/bootstrapvalidator/issues/578), [#813](https://github.com/nghuuphuoc/bootstrapvalidator/pull/813): The [stringLength](http://bootstrapvalidator.com/validators/stringLength/) validator supports HTML 5 ```minlength``` attribute, thanks to [@emilchristensen](https://github.com/emilchristensen)
 * [#675](https://github.com/nghuuphuoc/bootstrapvalidator/pull/675): The [emailAddress](http://bootstrapvalidator.com/validators/emailAddress/) validator accepts multiple email addresses, thanks to [@kenny-evitt](https://github.com/kenny-evitt)
 * [#716](https://github.com/nghuuphuoc/bootstrapvalidator/issues/716), [#765](https://github.com/nghuuphuoc/bootstrapvalidator/issues/765): Reuse data returned by [callback](http://bootstrapvalidator.com/validators/callback/), [remote](http://bootstrapvalidator.com/validators/remote/), custom validators
 * [#734](https://github.com/nghuuphuoc/bootstrapvalidator/pull/734): The [uri](http://bootstrapvalidator.com/validators/uri/) validator adds support for custom protocol, thanks to [@bcamarneiro](https://github.com/bcamarneiro)

+ 1 - 1
demo/html5.html

@@ -43,7 +43,7 @@
                                    data-bv-message="The username is not valid"
                                    required data-bv-notempty-message="The username is required and cannot be empty"
                                    pattern="[a-zA-Z0-9_\.]+" data-bv-regexp-message="The username can only consist of alphabetical, number, dot and underscore"
-                                   minlength="5" />
+                                   minlength="5" data-bv-stringlength-message="The username must have at least 5 characters" />
                         </div>
                     </div>
 

+ 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.2-dev, built on 2014-09-10 12:12:27 PM
+ * @version     v0.5.2-dev, built on 2014-09-10 7:47:26 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 8 - 8
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.2-dev, built on 2014-09-10 12:12:27 PM
+ * @version     v0.5.2-dev, built on 2014-09-10 7:47:26 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -5924,17 +5924,17 @@ if (typeof jQuery === 'undefined') {
         },
 
         enableByHtml5: function($field) {
-            var html5Validators = {};
-            var maxLength = $field.attr('maxlength');
+            var options   = {},
+                maxLength = $field.attr('maxlength'),
+                minLength = $field.attr('minlength');
             if (maxLength) {
-                html5Validators.max = parseInt(maxLength, 10);
+                options.max = parseInt(maxLength, 10);
             }
-
-            var minLength = $field.attr('minlength');
             if (minLength) {
-                html5Validators.min = parseInt(minLength, 10);
+                options.min = parseInt(minLength, 10);
             }
-            return !$.isEmptyObject(html5Validators) && html5Validators;
+            
+            return $.isEmptyObject(options) ? false : options;
         },
 
         /**

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


+ 7 - 7
src/js/validator/stringLength.js

@@ -14,17 +14,17 @@
         },
 
         enableByHtml5: function($field) {
-            var html5Validators = {};
-            var maxLength = $field.attr('maxlength');
+            var options   = {},
+                maxLength = $field.attr('maxlength'),
+                minLength = $field.attr('minlength');
             if (maxLength) {
-                html5Validators.max = parseInt(maxLength, 10);
+                options.max = parseInt(maxLength, 10);
             }
-
-            var minLength = $field.attr('minlength');
             if (minLength) {
-                html5Validators.min = parseInt(minLength, 10);
+                options.min = parseInt(minLength, 10);
             }
-            return !$.isEmptyObject(html5Validators) && html5Validators;
+
+            return $.isEmptyObject(options) ? false : options;
         },
 
         /**