diff options
| author | Jacob Thornton <[email protected]> | 2012-03-08 11:14:56 -0800 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-03-08 11:14:56 -0800 |
| commit | 26e683f1d0b7baedd161d928501043c1a7880445 (patch) | |
| tree | 1b7dbc0407e86318fefaf2512a2612233872700f | |
| parent | 426feeef6a4cf251431c7a21a1c79b0477ef37a0 (diff) | |
| parent | 3a6f58598cdad40916426f31564afada6c7b4bdc (diff) | |
| download | bootstrap-26e683f1d0b7baedd161d928501043c1a7880445.tar.xz bootstrap-26e683f1d0b7baedd161d928501043c1a7880445.zip | |
Merge pull request #2177 from phopkins/typeahead_friendly
[2.0.2-wip] Typeahead friendly
| -rw-r--r-- | js/bootstrap-typeahead.js | 12 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-typeahead.js | 6 |
2 files changed, 11 insertions, 7 deletions
diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 503155950..99f84f796 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -40,6 +40,7 @@ , select: function () { var val = this.$menu.find('.active').attr('data-value') this.$element.val(val) + this.$element.change(); return this.hide() } @@ -165,9 +166,6 @@ } , keyup: function (e) { - e.stopPropagation() - e.preventDefault() - switch(e.keyCode) { case 40: // down arrow case 38: // up arrow @@ -180,6 +178,7 @@ break case 27: // escape + if (!this.shown) return this.hide() break @@ -187,10 +186,11 @@ this.lookup() } + e.stopPropagation() + e.preventDefault() } , keypress: function (e) { - e.stopPropagation() if (!this.shown) return switch(e.keyCode) { @@ -210,12 +210,12 @@ this.next() break } + + e.stopPropagation() } , blur: function (e) { var that = this - e.stopPropagation() - e.preventDefault() setTimeout(function () { that.hide() }, 150) } diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 455ed415b..96ea7c45f 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -114,15 +114,19 @@ $(function () { source: ['aa', 'ab', 'ac'] }) , typeahead = $input.data('typeahead') + , changed = false $input.val('a') typeahead.lookup() + $input.change(function() { changed = true }); + $(typeahead.$menu.find('li')[2]).mouseover().click() equals($input.val(), 'ac', 'input value was correctly set') ok(!typeahead.$menu.is(':visible'), 'the menu was hidden') + ok(changed, 'a change event was fired') typeahead.$menu.remove() }) -})
\ No newline at end of file +}) |
