From 19f535f0400bfafe8297026671dcb5cc6ac572a0 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 16 Sep 2010 00:49:31 -0700 Subject: [PATCH 1/2] Autocomplete: added additional keyPress handler to prevent form submit in opera. Fixed #6055 (keyDown event doesn't prevent form from submit) --- ui/jquery.ui.autocomplete.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 6cdbb4db7b3..630fbe27eb1 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -43,6 +43,7 @@ $.widget( "ui.autocomplete", { return; } + var suppressKeyPress = false; var keyCode = $.ui.keyCode; switch( event.keyCode ) { case keyCode.PAGE_UP: @@ -65,6 +66,7 @@ $.widget( "ui.autocomplete", { case keyCode.NUMPAD_ENTER: // when menu is open or has focus if ( self.menu.element.is( ":visible" ) ) { + suppressKeyPress = true; event.preventDefault(); } //passthrough - ENTER and TAB both select the current element @@ -91,6 +93,12 @@ $.widget( "ui.autocomplete", { break; } }) + .bind( "keypress.autocomplete", function(event) { + if(suppressKeyPress) { + suppressKeyPress = false; + event.preventDefault(); + } + }) .bind( "focus.autocomplete", function() { if ( self.options.disabled ) { return; From b8333ed77a4bd520f057881024713c6a8b2ae2a3 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 4 Oct 2010 14:03:20 -0700 Subject: [PATCH 2/2] update fix for #6055 (keyDown event doesn't prevent form from submit). Move suppressKeyPress declaration to the upper scope --- ui/jquery.ui.autocomplete.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 630fbe27eb1..1ded2539663 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -28,7 +28,8 @@ $.widget( "ui.autocomplete", { }, _create: function() { var self = this, - doc = this.element[ 0 ].ownerDocument; + doc = this.element[ 0 ].ownerDocument, + suppressKeyPress = false; this.element .addClass( "ui-autocomplete-input" ) .attr( "autocomplete", "off" ) @@ -43,7 +44,7 @@ $.widget( "ui.autocomplete", { return; } - var suppressKeyPress = false; + suppressKeyPress = false; var keyCode = $.ui.keyCode; switch( event.keyCode ) { case keyCode.PAGE_UP: