Browse Source

Merge pull request #1041 from jazzzz/ie-input-fix

Ignore bogus events on IE (fixes #1040)
Phuoc Nguyen 11 years ago
parent
commit
5eab784d3b
2 changed files with 50 additions and 1 deletions
  1. 5 1
      src/js/bootstrapValidator.js
  2. 45 0
      test/spec/input.js

+ 5 - 1
src/js/bootstrapValidator.js

@@ -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) {
+                        // ignore bogus input events on IE
+                        if ('input' === e.type && document.activeElement !== this) {
+                            return;
+                        }
                         if (that._exceedThreshold($(this))) {
                             that.validateField($(this));
                         }

+ 45 - 0
test/spec/input.js

@@ -0,0 +1,45 @@
+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">',
+                '<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="Café" />',
+                '</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
+    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([]);
+    });
+});