浏览代码

#1040, #1041: Input with placeholder shouldn't be validated on init (IE 10/11), thanks to @jazzzz

Phuoc Nguyen 11 年之前
父节点
当前提交
84685dc6b6

+ 2 - 1
CHANGELOG.md

@@ -23,9 +23,10 @@ __Improvements__
 * [#1017](https://github.com/nghuuphuoc/bootstrapvalidator/pull/1017): Enable validator when setting ```data-bv-validatorname="data-bv-validatorname"```, thanks to [@jazzzz](https://github.com/jazzzz)
 
 __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
+* [#933](https://github.com/nghuuphuoc/bootstrapvalidator/issues/933), [#959](https://github.com/nghuuphuoc/bootstrapvalidator/issues/959), [#1047](https://github.com/nghuuphuoc/bootstrapvalidator/issues/1047): Tooltip/popover isn't destroyed when the field is valid
 * [#991](https://github.com/nghuuphuoc/bootstrapvalidator/issues/991): The field is validated only one time when setting ```trigger: 'blur'```, ```container: 'tooltip'```
 * [#1014](https://github.com/nghuuphuoc/bootstrapvalidator/pull/1014): Fix [isValidField()](http://bootstrapvalidator.com/api/#is-valid-field) and [validateField()](http://bootstrapvalidator.com/api/#validate-field) methods for fields without validators, thanks to [@jazzzz](https://github.com/jazzzz)
+* [#1040](https://github.com/nghuuphuoc/bootstrapvalidator/issues/1040), [#1041](https://github.com/nghuuphuoc/bootstrapvalidator/pull/1041): Fix the issue where input with placeholder is auto validated on IE 10, 11, thanks to [@jazzzz](https://github.com/jazzzz)
 
 __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)

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

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.3-dev, built on 2014-10-28 8:49:13 AM
+ * @version     v0.5.3-dev, built on 2014-10-30 10:35:35 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 6 - 2
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.3-dev, built on 2014-10-28 8:49:13 AM
+ * @version     v0.5.3-dev, built on 2014-10-30 10:35:35 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -449,7 +449,11 @@ if (typeof jQuery === 'undefined') {
                 case 'enabled':
                 /* falls through */
                 default:
-                    fields.off(events).on(events, function() {
+                    fields.off(events).on(events, function(e) {
+                        // #1040: The input with placeholder is auto validated on IE 10, 11
+                        if ('input' === e.type && document.activeElement !== this) {
+                            return;
+                        }
                         if (that._exceedThreshold($(this))) {
                             that.validateField($(this));
                         }

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


+ 1 - 1
src/js/bootstrapValidator.js

@@ -450,7 +450,7 @@ if (typeof jQuery === 'undefined') {
                 /* falls through */
                 default:
                     fields.off(events).on(events, function(e) {
-                        // ignore bogus input events on IE
+                        // #1040: The input with placeholder is auto validated on IE 10, 11
                         if ('input' === e.type && document.activeElement !== this) {
                             return;
                         }

+ 37 - 0
test/spec.js

@@ -1854,6 +1854,43 @@ describe('i18n', function() {
     });
 });
 
+describe('input', function() {
+    beforeEach(function(done) {
+        $([
+            '<form class="form-horizontal" id="inputForm">',
+                '<div class="form-group">',
+                    '<textarea name="text" data-bv-notempty placeholder="Text" />',
+                '</div>',
+                '<div class="form-group">',
+                    '<input type="text" name="input1" data-bv-notempty placeholder="Text" />',
+                '</div>',
+                '<div class="form-group">',
+                    '<input type="text" name="input2" data-bv-notempty placeholder="Text" />',
+                '</div>',
+            '</form>'
+        ].join('\n')).appendTo('body');
+
+        $('#inputForm').bootstrapValidator();
+
+        this.bv      = $('#inputForm').data('bootstrapValidator');
+        this.$text   = this.bv.getFieldElements('text');
+        this.$input1 = this.bv.getFieldElements('input1');
+        this.$input2 = this.bv.getFieldElements('input2');
+        setTimeout(done, 0);
+    });
+
+    afterEach(function() {
+        $('#inputForm').bootstrapValidator('destroy').remove();
+    });
+
+    // #1040, #1041
+    it('Fields should not be validated on init', function() {
+        expect(this.bv.getMessages(this.$text)).toEqual([]);
+        expect(this.bv.getMessages(this.$input1)).toEqual([]);
+        expect(this.bv.getMessages(this.$input2)).toEqual([]);
+    });
+});
+
 describe('message', function() {
     beforeEach(function() {
         var html = [

+ 3 - 12
test/spec/input.js

@@ -1,13 +1,4 @@
 describe('input', function() {
-    // Override the options
-    $.extend($.fn.bootstrapValidator.DEFAULT_OPTIONS, {
-        feedbackIcons: {
-            valid: 'glyphicon glyphicon-ok',
-            invalid: 'glyphicon glyphicon-remove',
-            validating: 'glyphicon glyphicon-refresh'
-        }
-    });
-
     beforeEach(function(done) {
         $([
             '<form class="form-horizontal" id="inputForm">',
@@ -18,7 +9,7 @@ describe('input', function() {
                     '<input type="text" name="input1" data-bv-notempty placeholder="Text" />',
                 '</div>',
                 '<div class="form-group">',
-                    '<input type="text" name="input2" data-bv-notempty placeholder="Café" />',
+                    '<input type="text" name="input2" data-bv-notempty placeholder="Text" />',
                 '</div>',
             '</form>'
         ].join('\n')).appendTo('body');
@@ -36,8 +27,8 @@ describe('input', function() {
         $('#inputForm').bootstrapValidator('destroy').remove();
     });
 
-    // #1040
-    it('fields should not be validated on init', function() {
+    // #1040, #1041
+    it('Fields should not be validated on init', function() {
         expect(this.bv.getMessages(this.$text)).toEqual([]);
         expect(this.bv.getMessages(this.$input1)).toEqual([]);
         expect(this.bv.getMessages(this.$input2)).toEqual([]);