Browse Source

#82: The errors aren't shown if the form has no labels

nghuuphuoc 11 years ago
parent
commit
fffc48354d

+ 1 - 1
README.md

@@ -313,7 +313,7 @@ max         | n/a     | The maximum length. One of ```min```, ```max``` options
 
 
 ## API
 ## API
 
 
-### ```validate()```
+### ```validate```
 
 
 ```validate()```: Validate form manually. It is useful when you want to validate form by clicking a button or a link instead of a submit buttons.
 ```validate()```: Validate form manually. It is useful when you want to validate form by clicking a button or a link instead of a submit buttons.
 
 

+ 5 - 0
demo/formWithoutLabels.html

@@ -51,6 +51,11 @@
 $(document).ready(function() {
 $(document).ready(function() {
     $('#defaultForm').bootstrapValidator({
     $('#defaultForm').bootstrapValidator({
         message: 'This value is not valid',
         message: 'This value is not valid',
+        feedbackIcons: {
+            valid: 'glyphicon glyphicon-ok',
+            invalid: 'glyphicon glyphicon-remove',
+            validating: 'glyphicon glyphicon-refresh'
+        },
         fields: {
         fields: {
             username: {
             username: {
                 message: 'The username is not valid',
                 message: 'The username is not valid',

+ 19 - 16
dist/js/bootstrapValidator.js

@@ -169,29 +169,32 @@
                 }
                 }
             }
             }
 
 
-            if (size && offset) {
-                for (var validatorName in this.options.fields[field].validators) {
-                    if (!$.fn.bootstrapValidator.validators[validatorName]) {
-                        delete this.options.fields[field].validators[validatorName];
-                        continue;
-                    }
-
-                    this.results[field][validatorName] = this.STATUS_NOT_VALIDATED;
-                    $('<small/>')
-                        .css('display', 'none')
-                        .attr('data-bs-validator', validatorName)
-                        .addClass('help-block')
-                        .addClass(['col-', size, '-offset-', offset].join(''))
-                        .addClass(['col-', size, '-', this.options.columns - offset].join(''))
-                        .appendTo($parent);
+            for (var validatorName in this.options.fields[field].validators) {
+                if (!$.fn.bootstrapValidator.validators[validatorName]) {
+                    delete this.options.fields[field].validators[validatorName];
+                    continue;
                 }
                 }
+
+                this.results[field][validatorName] = this.STATUS_NOT_VALIDATED;
+                $('<small/>')
+                    .css('display', 'none')
+                    .attr('data-bs-validator', validatorName)
+                    .addClass('help-block')
+                    .addClass(size && offset ? ['col-', size, '-offset-', offset].join('') : '')
+                    .addClass(size && offset ? ['col-', size, '-', this.options.columns - offset].join('') : '')
+                    .appendTo($parent);
             }
             }
 
 
             // Prepare the feedback icons
             // Prepare the feedback icons
             // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
             // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
             if (this.options.feedbackIcons) {
             if (this.options.feedbackIcons) {
                 $parent.addClass('has-feedback');
                 $parent.addClass('has-feedback');
-                $('<i/>').css('display', 'none').addClass('form-control-feedback').insertAfter($(fields[fields.length - 1]));
+                var $icon = $('<i/>').css('display', 'none').addClass('form-control-feedback').insertAfter($(fields[fields.length - 1]));
+                // The feedback icon does not render correctly if there is no label
+                // https://github.com/twbs/bootstrap/issues/12873
+                if (label == null) {
+                    $icon.css('top', 0);
+                }
             }
             }
 
 
             if (this.options.fields[field]['enabled'] == null) {
             if (this.options.fields[field]['enabled'] == null) {

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


+ 19 - 16
src/js/bootstrapValidator.js

@@ -168,29 +168,32 @@
                 }
                 }
             }
             }
 
 
-            if (size && offset) {
-                for (var validatorName in this.options.fields[field].validators) {
-                    if (!$.fn.bootstrapValidator.validators[validatorName]) {
-                        delete this.options.fields[field].validators[validatorName];
-                        continue;
-                    }
-
-                    this.results[field][validatorName] = this.STATUS_NOT_VALIDATED;
-                    $('<small/>')
-                        .css('display', 'none')
-                        .attr('data-bs-validator', validatorName)
-                        .addClass('help-block')
-                        .addClass(['col-', size, '-offset-', offset].join(''))
-                        .addClass(['col-', size, '-', this.options.columns - offset].join(''))
-                        .appendTo($parent);
+            for (var validatorName in this.options.fields[field].validators) {
+                if (!$.fn.bootstrapValidator.validators[validatorName]) {
+                    delete this.options.fields[field].validators[validatorName];
+                    continue;
                 }
                 }
+
+                this.results[field][validatorName] = this.STATUS_NOT_VALIDATED;
+                $('<small/>')
+                    .css('display', 'none')
+                    .attr('data-bs-validator', validatorName)
+                    .addClass('help-block')
+                    .addClass(size && offset ? ['col-', size, '-offset-', offset].join('') : '')
+                    .addClass(size && offset ? ['col-', size, '-', this.options.columns - offset].join('') : '')
+                    .appendTo($parent);
             }
             }
 
 
             // Prepare the feedback icons
             // Prepare the feedback icons
             // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
             // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
             if (this.options.feedbackIcons) {
             if (this.options.feedbackIcons) {
                 $parent.addClass('has-feedback');
                 $parent.addClass('has-feedback');
-                $('<i/>').css('display', 'none').addClass('form-control-feedback').insertAfter($(fields[fields.length - 1]));
+                var $icon = $('<i/>').css('display', 'none').addClass('form-control-feedback').insertAfter($(fields[fields.length - 1]));
+                // The feedback icon does not render correctly if there is no label
+                // https://github.com/twbs/bootstrap/issues/12873
+                if (label == null) {
+                    $icon.css('top', 0);
+                }
             }
             }
 
 
             if (this.options.fields[field]['enabled'] == null) {
             if (this.options.fields[field]['enabled'] == null) {