Browse Source

Merge pull request #1017 from jazzzz/html5-boolean-attributes

Allow boolean attributes conforming to the HTML 5 spec
Phuoc Nguyen 11 years ago
parent
commit
dc18290ed2
1 changed files with 8 additions and 4 deletions
  1. 8 4
      src/js/bootstrapValidator.js

+ 8 - 4
src/js/bootstrapValidator.js

@@ -176,19 +176,22 @@ if (typeof jQuery === 'undefined') {
                 validators = {},
                 validator,
                 v,          // Validator name
+                attrName,
                 enabled,
                 optionName,
+                optionAttrName,
                 optionValue,
                 html5AttrName,
                 html5AttrMap;
 
             for (v in $.fn.bootstrapValidator.validators) {
                 validator    = $.fn.bootstrapValidator.validators[v];
-                enabled      = $field.attr('data-bv-' + v.toLowerCase()) + '';
+                attrName     = 'data-bv-' + v.toLowerCase(),
+                enabled      = $field.attr(attrName) + '';
                 html5AttrMap = ('function' === typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;
 
                 if ((html5AttrMap && enabled !== 'false')
-                    || (html5AttrMap !== true && ('' === enabled || 'true' === enabled)))
+                    || (html5AttrMap !== true && ('' === enabled || 'true' === enabled || attrName === enabled.toLowerCase())))
                 {
                     // Try to parse the options via attributes
                     validator.html5Attributes = $.extend({}, { message: 'message', onerror: 'onError', onsuccess: 'onSuccess' }, validator.html5Attributes);
@@ -196,9 +199,10 @@ if (typeof jQuery === 'undefined') {
 
                     for (html5AttrName in validator.html5Attributes) {
                         optionName  = validator.html5Attributes[html5AttrName];
-                        optionValue = $field.attr('data-bv-' + v.toLowerCase() + '-' + html5AttrName);
+                        optionAttrName = 'data-bv-' + v.toLowerCase() + '-' + html5AttrName,
+                        optionValue = $field.attr(optionAttrName);
                         if (optionValue) {
-                            if ('true' === optionValue) {
+                            if ('true' === optionValue || optionAttrName === optionValue.toLowerCase()) {
                                 optionValue = true;
                             } else if ('false' === optionValue) {
                                 optionValue = false;