Browse Source

#14, #57: Support maxlength attribute

phuoc 12 years ago
parent
commit
6f00528a8d

+ 7 - 0
demo/html5.html

@@ -71,6 +71,13 @@
                     </div>
 
                     <div class="form-group">
+                        <label class="col-lg-3 control-label">Bio</label>
+                        <div class="col-lg-5">
+                            <textarea class="form-control" name="bio" rows="10" data-bv-stringlength data-bv-stringlength-max="200" data-bv-stringlength-message="The bio must be less than 200 characters long"></textarea>
+                        </div>
+                    </div>
+
+                    <div class="form-group">
                         <div class="col-lg-9 col-lg-offset-3">
                             <button type="submit" class="btn btn-primary">Sign up</button>
                         </div>

+ 11 - 0
dist/js/bootstrapValidator.js

@@ -1569,6 +1569,17 @@
     $.fn.bootstrapValidator.validators.stringLength = {
         html5Attributes: ['message', 'min', 'max'],
 
+        enableByHtml5: function($field) {
+            var maxLength = $field.attr('maxlength');
+            if (maxLength) {
+                return {
+                    max: parseInt(maxLength, 10)
+                };
+            }
+
+            return true;
+        },
+
         /**
          * Check if the length of element value is less or more than given number
          *

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


+ 11 - 0
src/js/validator/stringLength.js

@@ -2,6 +2,17 @@
     $.fn.bootstrapValidator.validators.stringLength = {
         html5Attributes: ['message', 'min', 'max'],
 
+        enableByHtml5: function($field) {
+            var maxLength = $field.attr('maxlength');
+            if (maxLength) {
+                return {
+                    max: parseInt(maxLength, 10)
+                };
+            }
+
+            return true;
+        },
+
         /**
          * Check if the length of element value is less or more than given number
          *