From 80d03e143ce3041e9c3ec63db439ee7738679573 Mon Sep 17 00:00:00 2001 From: Pete Hopkins Date: Mon, 30 Jan 2012 12:11:17 -0500 Subject: [PATCH 1/3] Allow events to propagate / default if not used. - All key events when the menu is not shown now propagate. - Blur is also allowed to propagate. --- js/bootstrap-typeahead.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 5031559507..c5776df133 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -165,9 +165,6 @@ } , keyup: function (e) { - e.stopPropagation() - e.preventDefault() - switch(e.keyCode) { case 40: // down arrow case 38: // up arrow @@ -187,10 +184,11 @@ this.lookup() } + e.stopPropagation() + e.preventDefault() } , keypress: function (e) { - e.stopPropagation() if (!this.shown) return switch(e.keyCode) { @@ -210,12 +208,12 @@ this.next() break } + + e.stopPropagation() } , blur: function (e) { var that = this - e.stopPropagation() - e.preventDefault() setTimeout(function () { that.hide() }, 150) } From 70fecd111566eec3136457afb4143d0950c455b5 Mon Sep 17 00:00:00 2001 From: Pete Hopkins Date: Mon, 30 Jan 2012 12:13:18 -0500 Subject: [PATCH 2/3] Fires change event when element is selected from menu --- js/bootstrap-typeahead.js | 1 + js/tests/unit/bootstrap-typeahead.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index c5776df133..df1487bf82 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() } diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 455ed415b7..96ea7c45fc 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 +}) From 3a6f58598cdad40916426f31564afada6c7b4bdc Mon Sep 17 00:00:00 2001 From: Pete Hopkins Date: Tue, 31 Jan 2012 09:23:58 -0500 Subject: [PATCH 3/3] Allows escape to bubble when menu isn't shown --- js/bootstrap-typeahead.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index df1487bf82..99f84f7961 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -178,6 +178,7 @@ break case 27: // escape + if (!this.shown) return this.hide() break