浏览代码

#933, #959: Tooltip/popover isn't destroyed when the field is valid

Phuoc Nguyen 11 年之前
父节点
当前提交
0a47e8dd57

+ 3 - 0
CHANGELOG.md

@@ -7,6 +7,9 @@ __New Features__
 * [#822](https://github.com/nghuuphuoc/bootstrapvalidator/pull/822): Add color validator, thanks to [@emilchristensen](https://github.com/emilchristensen)
 * [#822](https://github.com/nghuuphuoc/bootstrapvalidator/pull/822): Add color validator, thanks to [@emilchristensen](https://github.com/emilchristensen)
 * [#844](https://github.com/nghuuphuoc/bootstrapvalidator/pull/844), [#874](https://github.com/nghuuphuoc/bootstrapvalidator/pull/874): The [stringLength](http://bootstrapvalidator.com/validators/stringLength/) validator adds option to evaluate length in UTF-8 bytes, thanks to [@thx2001r](https://github.com/thx2001r)
 * [#844](https://github.com/nghuuphuoc/bootstrapvalidator/pull/844), [#874](https://github.com/nghuuphuoc/bootstrapvalidator/pull/874): The [stringLength](http://bootstrapvalidator.com/validators/stringLength/) validator adds option to evaluate length in UTF-8 bytes, thanks to [@thx2001r](https://github.com/thx2001r)
 
 
+__Bug Fixes__
+* [#933](https://github.com/nghuuphuoc/bootstrapvalidator/issues/933), [#959](https://github.com/nghuuphuoc/bootstrapvalidator/issues/959): Tooltip/popover isn't destroyed when the field is valid
+
 __Document__
 __Document__
 * [#848](https://github.com/nghuuphuoc/bootstrapvalidator/pull/848): Update the [stringLength](http://bootstrapvalidator.com/validators/stringLength) document, thanks to [@Relequestual](https://github.com/Relequestual)
 * [#848](https://github.com/nghuuphuoc/bootstrapvalidator/pull/848): Update the [stringLength](http://bootstrapvalidator.com/validators/stringLength) document, thanks to [@Relequestual](https://github.com/Relequestual)
 * [#912](https://github.com/nghuuphuoc/bootstrapvalidator/issues/912): Add [Using language package](http://bootstrapvalidator.com/examples/using-language-package/) example
 * [#912](https://github.com/nghuuphuoc/bootstrapvalidator/issues/912): Add [Using language package](http://bootstrapvalidator.com/examples/using-language-package/) example

+ 73 - 0
demo/tooltip.html

@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>BootstrapValidator demo</title>
+
+    <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
+    <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
+
+    <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
+    <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
+    <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
+</head>
+<body>
+    <div class="container">
+        <div class="row">
+            <section>
+                <div class="col-sm-8 col-sm-offset-2">
+                    <div class="page-header">
+                        <h2>Tooltip container</h2>
+                    </div>
+
+                    <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
+                        <div class="form-group">
+                            <label class="col-sm-3 control-label">Full name</label>
+                            <div class="col-sm-4">
+                                <input type="text" class="form-control" name="firstName" placeholder="First name" />
+                            </div>
+                        </div>
+
+                        <div class="form-group">
+                            <div class="col-sm-9 col-sm-offset-3">
+                                <button type="submit" class="btn btn-primary">Sign up</button>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </section>
+        </div>
+    </div>
+
+<script type="text/javascript">
+$(document).ready(function() {
+    $('#defaultForm').bootstrapValidator({
+        container: 'tooltip',
+        feedbackIcons: {
+            valid: 'glyphicon glyphicon-ok',
+            invalid: 'glyphicon glyphicon-remove',
+            validating: 'glyphicon glyphicon-refresh'
+        },
+        fields: {
+            firstName: {
+                validators: {
+                    stringLength: {
+                        enabled: false,
+                        min: 4,
+                        message: 'The first name must be more than 5 characters'
+                    },
+                    notEmpty: {
+                        message: 'The first name is required'
+                    },
+                    regexp: {
+                        enabled: true,
+                        regexp: /^[a-z]+$/i,
+                        message: 'The first name must consist of a-z, A-Z characters only'
+                    }
+                }
+            }
+        }
+    });
+});
+</script>
+</body>
+</html>

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
  *
- * @version     v0.5.3-dev, built on 2014-10-17 2:40:04 PM
+ * @version     v0.5.3-dev, built on 2014-10-20 2:17:50 PM
  * @author      https://twitter.com/nghuuphuoc
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
  * @license     MIT

+ 3 - 3
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
  *
- * @version     v0.5.3-dev, built on 2014-10-17 2:40:04 PM
+ * @version     v0.5.3-dev, built on 2014-10-20 2:17:51 PM
  * @author      https://twitter.com/nghuuphuoc
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
  * @license     MIT
@@ -1084,7 +1084,7 @@ if (typeof jQuery === 'undefined') {
                                     placement: 'top',
                                     placement: 'top',
                                     title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
                                     title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
                                 })
                                 })
-                                : $icon.tooltip('hide');
+                                : $icon.css('cursor', '').tooltip('destroy');
                         break;
                         break;
                     // ... or popover
                     // ... or popover
                     case ($icon && 'popover' === container):
                     case ($icon && 'popover' === container):
@@ -1096,7 +1096,7 @@ if (typeof jQuery === 'undefined') {
                                     placement: 'top',
                                     placement: 'top',
                                     trigger: 'hover click'
                                     trigger: 'hover click'
                                 })
                                 })
-                                : $icon.popover('hide');
+                                : $icon.css('cursor', '').popover('destroy');
                         break;
                         break;
                     default:
                     default:
                         (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
                         (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();

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


+ 2 - 2
src/js/bootstrapValidator.js

@@ -1084,7 +1084,7 @@ if (typeof jQuery === 'undefined') {
                                     placement: 'top',
                                     placement: 'top',
                                     title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
                                     title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
                                 })
                                 })
-                                : $icon.tooltip('hide');
+                                : $icon.css('cursor', '').tooltip('destroy');
                         break;
                         break;
                     // ... or popover
                     // ... or popover
                     case ($icon && 'popover' === container):
                     case ($icon && 'popover' === container):
@@ -1096,7 +1096,7 @@ if (typeof jQuery === 'undefined') {
                                     placement: 'top',
                                     placement: 'top',
                                     trigger: 'hover click'
                                     trigger: 'hover click'
                                 })
                                 })
-                                : $icon.popover('hide');
+                                : $icon.css('cursor', '').popover('destroy');
                         break;
                         break;
                     default:
                     default:
                         (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
                         (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();

+ 4 - 4
test/spec.js

@@ -235,8 +235,8 @@ describe('container tooltip/popover', function() {
         this.$firstName.val('First');
         this.$firstName.val('First');
         this.$lastName.val('Last');
         this.$lastName.val('Last');
         this.bv.validate();
         this.bv.validate();
-        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
-        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
+        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
     });
     });
 
 
     it('container programmatically', function() {
     it('container programmatically', function() {
@@ -263,8 +263,8 @@ describe('container tooltip/popover', function() {
         this.$firstName.val('First');
         this.$firstName.val('First');
         this.$lastName.val('Last');
         this.$lastName.val('Last');
         this.bv.validate();
         this.bv.validate();
-        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
-        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
+        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
     });
     });
 });
 });
 
 

+ 4 - 4
test/spec/container.js

@@ -168,8 +168,8 @@ describe('container tooltip/popover', function() {
         this.$firstName.val('First');
         this.$firstName.val('First');
         this.$lastName.val('Last');
         this.$lastName.val('Last');
         this.bv.validate();
         this.bv.validate();
-        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
-        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
+        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
     });
     });
 
 
     it('container programmatically', function() {
     it('container programmatically', function() {
@@ -196,7 +196,7 @@ describe('container tooltip/popover', function() {
         this.$firstName.val('First');
         this.$firstName.val('First');
         this.$lastName.val('Last');
         this.$lastName.val('Last');
         this.bv.validate();
         this.bv.validate();
-        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
-        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
+        expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
     });
     });
 });
 });