ソースを参照

Merge branch 'leedorian-master'

Phuoc Nguyen 11 年 前
コミット
d5a13dfcb8
1 ファイル変更22 行追加4 行削除
  1. 22 4
      src/js/bootstrapValidator.js

+ 22 - 4
src/js/bootstrapValidator.js

@@ -293,7 +293,7 @@
                 $field.off(events).on(events, function() {
                     that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
                 });
-
+                
                 // Create help block elements for showing the error messages
                 $field.data('bv.messages', $message);
                 for (validatorName in this.options.fields[field].validators) {
@@ -335,7 +335,9 @@
                     && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
                     && (!updateAll || i === total - 1))
                 {
-                    $parent.removeClass('has-success').removeClass('has-error').addClass('has-feedback');
+                    // $parent.removeClass('has-success').removeClass('has-error').addClass('has-feedback');
+                    // Keep error messages which are populated from back-end
+                    $parent.addClass('has-feedback');
                     var $icon = $('<i/>')
                                     .css('display', 'none')
                                     .addClass('form-control-feedback')
@@ -363,6 +365,22 @@
                         $icon.addClass('bv-icon-input-group')
                              .insertAfter($parent.find('.input-group').eq(0));
                     }
+                    
+                    // Show tooltip or popover message when focusing on the field
+                    if (container) {
+                        $field.off('focus.bv').on('focus.bv', function() {
+                            switch (container) {
+                                case 'tooltip':
+                                    $icon.tooltip('show');
+                                    break;
+                                case 'popover':
+                                    $icon.popover('show');
+                                    break;
+                                default:
+                                    break;
+                            }
+                        });
+                    }
                 }
             }
 
@@ -1001,7 +1019,7 @@
                                     placement: 'top',
                                     title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
                                 })
-                                : $icon.css('cursor', '').tooltip('destroy');
+                                : $icon.tooltip('hide');
                         break;
                     // ... or popover
                     case ($icon && 'popover' === container):
@@ -1013,7 +1031,7 @@
                                     placement: 'top',
                                     trigger: 'hover click'
                                 })
-                                : $icon.css('cursor', '').popover('destroy');
+                                : $icon.popover('hide');
                         break;
                     default:
                         (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();