aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/autocomplete/autocomplete_core.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2010-09-27 10:10:00 -0400
committerScott González <scott.gonzalez@gmail.com>2010-09-27 10:10:00 -0400
commitadcafce7a24156c503061eb354867e41064fd89f (patch)
treebcb0a933335f118161da3fe9589e54af5c51e5b4 /tests/unit/autocomplete/autocomplete_core.js
parentdda7bcb6383ed0fee9dcd1ae5f0a6e1dcc160c6b (diff)
downloadjquery-ui-adcafce7a24156c503061eb354867e41064fd89f.tar.gz
jquery-ui-adcafce7a24156c503061eb354867e41064fd89f.zip
Autocomplete: Only prevent the default action for enter when a menu item is active. Fixes #6038 - Autocomplete: Allow default behaviour on enter when menu is open but inactive.
Thanks Ján Suchal.
Diffstat (limited to 'tests/unit/autocomplete/autocomplete_core.js')
-rw-r--r--tests/unit/autocomplete/autocomplete_core.js33
1 files changed, 31 insertions, 2 deletions
diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js
index 9b8709abb..fcd835d1a 100644
--- a/tests/unit/autocomplete/autocomplete_core.js
+++ b/tests/unit/autocomplete/autocomplete_core.js
@@ -23,7 +23,7 @@ test("close-on-blur is properly delayed", function() {
same( $(".ui-menu:visible").length, 0 );
start();
}, 200);
-})
+});
test("close-on-blur is cancelled when starting a search", function() {
var ac = $("#autocomplete").autocomplete({
@@ -38,6 +38,35 @@ test("close-on-blur is cancelled when starting a search", function() {
same( $(".ui-menu:visible").length, 1 );
start();
}, 200);
-})
+});
+
+test( "prevent form submit on enter when menu is active", function() {
+ var event;
+ var ac = $( "#autocomplete" ).autocomplete({
+ source: [ "java", "javascript" ]
+ }).val( "ja" ).autocomplete( "search" );
+
+ event = $.Event( "keydown" );
+ event.keyCode = $.ui.keyCode.DOWN;
+ ac.trigger( event );
+ same( $( ".ui-menu-item:has(.ui-state-hover)" ).length, 1, "menu item is active" );
+
+ event = $.Event( "keydown" );
+ event.keyCode = $.ui.keyCode.ENTER;
+ ac.trigger( event );
+ ok( event.isDefaultPrevented(), "default action is prevented" );
+});
+
+test( "allow form submit on enter when menu is not active", function() {
+ var event;
+ var ac = $( "#autocomplete" ).autocomplete({
+ source: [ "java", "javascript" ]
+ }).val( "ja" ).autocomplete( "search" );
+
+ event = $.Event( "keydown" );
+ event.keyCode = $.ui.keyCode.ENTER;
+ ac.trigger( event );
+ ok( !event.isDefaultPrevented(), "default action is prevented" );
+});
})(jQuery);