From f0ef35ce6ed4b6e2d17a299a5ee250c32f41ad56 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 5 Nov 2009 14:58:25 +0000 Subject: [PATCH] update to r10069 (try to detect auto completion on input fields and do not submit form if user uses enter key for auto completion instead of right arrow key) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10254 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/styles/prosilver/template/forum_fn.js | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/phpBB/styles/prosilver/template/forum_fn.js b/phpBB/styles/prosilver/template/forum_fn.js index 11e4315e2a..153f0c2ae5 100644 --- a/phpBB/styles/prosilver/template/forum_fn.js +++ b/phpBB/styles/prosilver/template/forum_fn.js @@ -317,6 +317,9 @@ function find_in_tree(node, tag, type, class_name) } } +var in_autocomplete = false; +var last_key_entered = ''; + /** * Usually used for onkeypress event, to submit a form on enter */ @@ -326,9 +329,27 @@ function submit_default_button(event, selector, class_name) if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) event.which = event.charCode || event.keyCode; + // Keycode is array down? + if (event.keyCode && event.keyCode == 40) + in_autocomplete = true; + + // Make sure we are not within an "autocompletion" field + if (in_autocomplete) + { + // If return pressed and key changed we reset the autocompletion + if (!last_key_entered || last_key_entered == event.which) + { + in_autocompletion = false; + return true; + } + } + // Keycode is not return, then return. ;) if (event.which != 13) + { + last_key_entered = event.which; return true; + } var current = selector['parentNode']; @@ -373,12 +394,29 @@ function apply_onkeypress_event() if (!default_button || default_button.length <= 0) return true; + // Keycode is array down? + if (e.keyCode && e.keyCode == 40) + in_autocomplete = true; + + // Make sure we are not within an "autocompletion" field + if (in_autocomplete) + { + // If return pressed and key changed we reset the autocompletion + if (!last_key_entered || last_key_entered == e.which) + { + in_autocompletion = false; + return true; + } + } + if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { default_button.click(); return false; } + last_key_entered = e.which; + return true; });